static function updateContactDetails(&$params, $delay = FALSE)
 {
     CRM_Mailchimp_Utils::checkDebug('Start-CRM_Mailchimp_Utils updateContactDetails $params', $params);
     CRM_Mailchimp_Utils::checkDebug('Start-CRM_Mailchimp_Utils updateContactDetails $delay', $delay);
     if (empty($params)) {
         return NULL;
     }
     $params['status'] = array('Added' => 0, 'Updated' => 0);
     $contactParams = array('version' => 3, 'contact_type' => 'Individual', 'first_name' => $params['FNAME'], 'last_name' => $params['LNAME'], 'email' => $params['EMAIL']);
     if ($delay) {
         //To avoid a new duplicate contact to be created as both profile and upemail events are happening at the same time
         sleep(20);
     }
     $contactids = CRM_Mailchimp_Utils::getContactFromEmail($params['EMAIL']);
     if (count($contactids) > 1) {
         CRM_Core_Error::debug_log_message('Mailchimp Pull/Webhook: Multiple contacts found for the email address ' . print_r($params['EMAIL'], true), $out = false);
         return NULL;
     }
     if (count($contactids) == 1) {
         $contactParams = CRM_Mailchimp_Utils::updateParamsExactMatch($contactids, $params);
         $params['status']['Updated'] = 1;
     }
     if (empty($contactids)) {
         //check for contacts with no primary email address
         $id = CRM_Mailchimp_Utils::getContactFromEmail($params['EMAIL'], FALSE);
         if (count($id) > 1) {
             CRM_Core_Error::debug_log_message('Mailchimp Pull/Webhook: Multiple contacts found for the email address which is not primary ' . print_r($params['EMAIL'], true), $out = false);
             return NULL;
         }
         if (count($id) == 1) {
             $contactParams = CRM_Mailchimp_Utils::updateParamsExactMatch($id, $params);
             $params['status']['Updated'] = 1;
         }
         // Else create new contact
         if (empty($id)) {
             $params['status']['Added'] = 1;
         }
     }
     // Create/Update Contact details
     $contactResult = civicrm_api('Contact', 'create', $contactParams);
     CRM_Mailchimp_Utils::checkDebug('End-CRM_Mailchimp_Utils updateContactDetails $params', $params);
     CRM_Mailchimp_Utils::checkDebug('End-CRM_Mailchimp_Utils updateContactDetails $delay', $delay);
     return $contactResult['id'];
 }