diff --git a/includes/http/Request.php b/includes/http/Request.php
index 8ad3ad7503e3c4a0efe39b8ee37093a4c9bc8d62..0a1ee077e51a8e49f938f657fb5aa551b59d96ad 100644
--- a/includes/http/Request.php
+++ b/includes/http/Request.php
@@ -57,14 +57,19 @@ class Vtiger_Request {
 			}
 		}
 		if($isJSON) {
-                    $decodeValue = json_decode($value, true);
-                    $value = json_last_error() ? $value : $decodeValue;
+                    $oldValue = Zend_Json::$useBuiltinEncoderDecoder;
+                    Zend_Json::$useBuiltinEncoderDecoder = false;
+                    $decodeValue = Zend_Json::decode($value);
+                    if(isset($decodeValue)) {
+                            $value = $decodeValue;
+                    }
+                    Zend_Json::$useBuiltinEncoderDecoder  = $oldValue;
+		}
+
+                //Handled for null because vtlib_purify returns empty string
+                if(!empty($value)){
+                    $value = vtlib_purify($value);
                 }
-                
-        //Handled for null because vtlib_purify returns empty string
-        if(!empty($value)){
-            $value = vtlib_purify($value);
-        }
 		return $value;
 	}
 
diff --git a/layouts/v7/modules/Vtiger/resources/Popup.js b/layouts/v7/modules/Vtiger/resources/Popup.js
index 62387f416e3df2c1306c7c733dfcf98e17778e79..0e7cf4b5576f6f1776728c0d52b3ea8e7818a9ca 100644
--- a/layouts/v7/modules/Vtiger/resources/Popup.js
+++ b/layouts/v7/modules/Vtiger/resources/Popup.js
@@ -531,6 +531,7 @@ jQuery.Class("Vtiger_Popup_Js",{
             jQuery('#searchvalue').val("");
             jQuery('#totalPageCount').text("");
 			thisInstance.searchHandler().then(function(data){
+                                thisInstance.writeSelectedIds(new Array());
 				jQuery('#pageNumber').val(1);
 				jQuery('#pageToJump').val(1);
 				thisInstance.updatePagination();
diff --git a/layouts/v7/modules/Vtiger/uitypes/Reference.tpl b/layouts/v7/modules/Vtiger/uitypes/Reference.tpl
index c82174b4ed0643ca0eea1cc5b91cd429d67520e4..75da18101a35b83ffbcbe3e7d985e7e56ac4a8ca 100644
--- a/layouts/v7/modules/Vtiger/uitypes/Reference.tpl
+++ b/layouts/v7/modules/Vtiger/uitypes/Reference.tpl
@@ -47,7 +47,7 @@
                 data-specific-rules='{ZEND_JSON::encode($FIELD_INFO["validator"])}'
             {/if}
             />
-        <a href="#" class="clearReferenceSelection {if $FIELD_VALUE eq 0}hide{/if}"> x </a>
+        <a href="#" class="clearReferenceSelection {if empty($FIELD_VALUE) || $FIELD_VALUE lte 0}hide{/if}"> x </a>
             <span class="input-group-addon relatedPopup cursorPointer" title="{vtranslate('LBL_SELECT', $MODULE)}">
                 <i id="{$MODULE}_editView_fieldName_{$FIELD_NAME}_select" class="fa fa-search"></i>
             </span>
diff --git a/modules/Emails/models/Record.php b/modules/Emails/models/Record.php
index 78e0e39c8419e4ed92e122107872f7d9f54e53a6..09370b417e34d7975bcde5d5cacde27772d0555f 100644
--- a/modules/Emails/models/Record.php
+++ b/modules/Emails/models/Record.php
@@ -57,7 +57,7 @@ class Emails_Record_Model extends Vtiger_Record_Model {
 		$userName = $currentUserModel->getName();
 
 		// To eliminate the empty value of an array
-		$toEmailInfo = array_filter($this->get('toemailinfo'));
+		$toEmailInfo = $this->get('toemailinfo') ? array_filter($this->get('toemailinfo')) : array();
 		$emailsInfo = array();
 		foreach ($toEmailInfo as $id => $emails) {
 			foreach($emails as $key => $value){
@@ -828,4 +828,4 @@ class Emails_Record_Model extends Vtiger_Record_Model {
 		}
 		return false;
 	}
-}
\ No newline at end of file
+}
diff --git a/vtlib/Vtiger/Utils.php b/vtlib/Vtiger/Utils.php
index 64a36a485a1aa660fd10408f1adef3ca5fd7430d..e5415688d6a1410ef652541f26a2dad7fd109941 100644
--- a/vtlib/Vtiger/Utils.php
+++ b/vtlib/Vtiger/Utils.php
@@ -342,7 +342,7 @@ class Vtiger_Utils {
     public static function writeLogFile($logFileName, $log) {
         if ($logFileName && $log) {
             $logFilePath = self::$logFolder . '/' . $logFileName;
-            file_put_contents($logFilePath, print_r($log, true), FILE_APPEND);
+            file_put_contents($logFilePath, print_r($log, true).PHP_EOL, FILE_APPEND);
         }
     }
 }