diff --git a/mailjet.module b/mailjet.module
index 79ac3d5..4edf852 100644
--- a/mailjet.module
+++ b/mailjet.module
@@ -419,41 +419,53 @@ function mailjet_properties_sync($newField = NULL, $delete = FALSE) {
 }
 
 /**
- * Sync user hooks.
+ * Add a Mailjet user.
+ *
+ * @param \Drupal\user\Entity\User $user
+ *   The User object.
  */
-function mailjet_user_insert($user) {
-    mailjet_sync_single_user($user, 'add');
+function mailjet_user_insert(User $user) {
+  ksm('mailjet_user_insert');
+  mailjet_sync_single_user($user, 'add');
 }
 
-
 /**
- * Updates Mailjet users
+ * Update a Mailjet user.
+ *
+ * @param \Drupal\user\Entity\User $user
+ *   The User object.
  */
-function mailjet_user_update($user) {
-    // Only trigger updates when the account status has changed.
-    if (isset($user->get('status')->value)) {
-        if ($user->get('status')->value > 0) { //should be the same as cancel hook
-            mailjet_sync_single_user($user, 'update');
-        }
-        else {
-            mailjet_sync_single_user($user, 'remove');
-        }
+function mailjet_user_update(User $user) {
+  // Only trigger updates when the account status has changed.
+  if (isset($user->get('status')->value)) {
+    if ($user->get('status')->value > 0) {
+      mailjet_sync_single_user($user, 'update');
+    }
+    else {
+      mailjet_sync_single_user($user, 'remove');
     }
+  }
 }
 
 /**
- * Deletes mailjet user.
+ * Delete a Mailjet user.
+ *
+ * @param \Drupal\user\Entity\User $user
+ *   The User object.
  */
-function mailjet_user_delete($user) {
-    mailjet_sync_single_user($user, 'remove');
-}
-
-function mailjet_user_cancel($user) {
-    mailjet_sync_single_user($user, 'remove');
+function mailjet_user_delete(User $user) {
+  mailjet_sync_single_user($user, 'remove');
 }
 
-
-function mailjet_sync_single_user($user, $type) {
+/**
+ * Sync a single Mailjet user.
+ *
+ * @param \Drupal\user\Entity\User $user
+ *   The User object.
+ * @param $action
+ *   The action to send to Mailjet.
+ */
+function mailjet_sync_single_user(User $user, $action) {
   $config_mailjet = \Drupal::config('mailjet.settings');
 
   if (empty($user->get('mail')->value)) {
@@ -462,76 +474,73 @@ function mailjet_sync_single_user($user, $type) {
 
   mailjet_properties_sync();
   $mailjetApiClient = mailjet_new();
-    //var_dump($infos->getEmail());
   $mj_lists = [];
-  //if (!empty($defaul_mj_list)) {
   $mj_lists[] = mailjet_get_default_list_id($mailjetApiClient);
-  //}
-//    var_dump($mj_lists);
-//    var_dump($type);
-//    var_dump($user);exit;
-  switch ($type) {
+  $fields = $user->getFields();
+
+  switch ($action) {
     case 'add':
     case 'update':
-      foreach ($mj_lists as $key => $value) {
-        // Get the data which we have to update. The data will be extracted from the user's object or $info variable
+      foreach ($mj_lists as $key => $list) {
+        $contact = [
+          'Email' => $user->get('mail')->value
+        ];
+
+        // Get the data which we have to update. The data will be extracted from
+        // the user's object.
         $data = [];
-        if (is_array($user) && isset($user[$infos['mail']])) {
-          foreach ($user[$infos['mail']]['properties'] as $prop_key => $prop_value) {
-            $data[str_replace("field_", "", $prop_key)] = $prop_value;
-          }
-        }
-        else {
-          foreach ($infos as $key => $info) {
-            if (strpos($key, 'field_') !== FALSE && isset($info['und'][0]['value'])) {
-              $data[str_replace("field_", "", $key)] =  $info['und'][0]['value'];
-            }
+
+        foreach ($fields as $field) {
+          if (substr( $field->getName(), 0, 6 ) === "field_") {
+            $data[str_replace("field_", "", $field->getName())] = $user->get($field->getName())->value;
           }
         }
 
-        $contact = [
-          'Email' => $user->get('mail')->value
-        ];
-        if (!empty($data)) {
-            $contact['Properties'] = $data;
+        if (count($data)) {
+          $contact['Properties'] = $data;
         }
-          //add new email
-        $response = MailjetApi::syncMailjetContact($value, $contact);
 
-        if (false != $response) {
-            \Drupal::logger('mailjet_messages')
-                ->notice(t('The new contact was added to list #' . $value . '.'));
+        // Add new contact.
+        $response = MailjetApi::syncMailjetContact($list, $contact);
+
+        if ($response) {
+          \Drupal::logger('mailjet_messages')
+            ->notice(t('The new contact was added to list #@list.', ['@list' => $list]));
         }
         else {
           \Drupal::logger('mailjet_messages')
-            ->notice(t('The new contact was not added to list #' . $value . '.'));
+            ->notice(t('The new contact was not added to list #@list.', ['@list' => $list]));
         }
       }
       break;
+
     case 'remove':
-      foreach ($mj_lists as $key => $value) {
+      foreach ($mj_lists as $key => $list) {
         $contact = [
           'Email' => $user->get('mail')->value
         ];
-        //add new email
-        $response = MailjetApi::syncMailjetContact($value, $contact, 'remove');
-        if (false == $response) {
+
+        // Remove contact.
+        $response = MailjetApi::syncMailjetContact($list, $contact, $action);
+
+        if ($response) {
           \Drupal::logger('mailjet_messages')
-            ->notice(t('The new contact was unsubscribed from list #' . $value . '.'));
+            ->notice(t('The contact was unsubscribed from list #@list.', ['@list' => $list]));
         }
         else {
           \Drupal::logger('mailjet_messages')
-            ->notice(t('The new contact was not unsubscribed from list #' . $value . '.'));
+            ->notice(t('The contact was not unsubscribed from list #@list.', ['@list' => $list]));
         }
       }
       break;
+
     default:
-      drupal_set_message(t("No user action"), "warning");
+      $messenger = \Drupal::messenger();
+      $messenger->addMessage(t('No user action'), 'warning');
       break;
   }
 }
 
-
 /**
  * Checks if batch process is running.
  */
@@ -734,35 +743,35 @@ function prepare_mail_template($email_header, $email_text_button, $email_descrip
   global $base_url;
   $tempalate = '<div style="width: 100%; background-color: white; box-shadow: 0px 0px 20px rgba(0, 0, 0, 0.35);">
     <table class="mockup-content paint-area" style="background-color: white; font-family: Ubuntu, Helvetica; border-collapse: collapse; width: 100%;">
-        <tbody>
-        <tr style="text-align: center; padding: 0 0 20px 0;">
-            <td style="height: 75px; line-height: 75px; width: 100%; vertical-align: middle;">
-                <span id="opt-in-subscribe-title" class="paint-area paint-area--text" contenteditable="true" style="font-family: Ubuntu, Helvetica; font-size: 18px; color: #333333; line-height: normal;"><b class="medium-b">' . $email_header . '</b></span>
-            </td>
-        </tr>
-        <tr>
-            <td style="height: 75px; line-height: 75px; width: 100%; vertical-align: middle; padding: 0 60px;">
-                <div id="opt-in-display-text" class="paint-area paint-area--text" style="text-align: center; color: grey; margin-bottom: 25px; line-height: normal;" contenteditable="true">' . $base_url . '</div></td></tr>
-        <tr>
-            <td><a rel="notrack" class="subscribe" href="' . $url . '" style="text-align: center;display: block;color: white;font-weight: 500;
-                font-size: 15px;background-color: #3da7ea;text-transform: uppercase;text-decoration: none;width: 260px;margin:
-                auto;border-radius: 5px;padding: 16px;">' . $email_text_button . '</a></td>
-        </tr>
-        <tr>
-            <td style="padding: 30px;" >
-                <span style="text-align: center;display: block; font-weight:bold; font-size:14px; text-decoration: none;">' . $email_description . '</span> <br />
-                <a rel="notrack" class="subscribe" href="' . $url . '" style="text-align: center;display: block;color: black; font-size: 12px; text-decoration: underline; margin: auto;">
-                   ' . $url . '
-                </a>
-            </td>
-        </tr>
-       
-	    <tr><td style="text-align: left; height: 75px; line-height: 75px; width: 100%; vertical-align: middle; padding: 0 60px;"><div id="opt-in-footer" class="paint-area paint-area--text" contenteditable="true" style="display: inline-block; font-family: Ubuntu, Helvetica; text-align: left; margin-bottom: 24px; color: grey; line-height: normal;"><i class="medium-i">' . $email_description_footer . '</i></div></td></tr>
-      
-	  
-        <tr><td style="text-align: left; padding: 0 60px; height: 30px; line-height: 30px;"><div id="opt-in-signature-top" class="paint-area paint-area--text" contenteditable="true" style="font-family: Ubuntu, Helvetica; display: inline-block; text-align: left; color: grey; line-height: normal;">' . $email_footer . '</div></td></tr>
-        <tr><td style="text-align: left; padding: 0 60px; height: 30px; line-height: 30px;"><div id="opt-in-signature-bottom" class="paint-area paint-area--text" contenteditable="true" style="font-family: Ubuntu, Helvetica; display: inline-block; text-align: left; color: grey; line-height: normal;"><b class="medium-b">' . $email_owner . '</b></div></td></tr>
-        </tbody>
+      <tbody>
+      <tr style="text-align: center; padding: 0 0 20px 0;">
+          <td style="height: 75px; line-height: 75px; width: 100%; vertical-align: middle;">
+              <span id="opt-in-subscribe-title" class="paint-area paint-area--text" contenteditable="true" style="font-family: Ubuntu, Helvetica; font-size: 18px; color: #333333; line-height: normal;"><b class="medium-b">' . $email_header . '</b></span>
+          </td>
+      </tr>
+      <tr>
+          <td style="height: 75px; line-height: 75px; width: 100%; vertical-align: middle; padding: 0 60px;">
+              <div id="opt-in-display-text" class="paint-area paint-area--text" style="text-align: center; color: grey; margin-bottom: 25px; line-height: normal;" contenteditable="true">' . $base_url . '</div></td></tr>
+      <tr>
+          <td><a rel="notrack" class="subscribe" href="' . $url . '" style="text-align: center;display: block;color: white;font-weight: 500;
+              font-size: 15px;background-color: #3da7ea;text-transform: uppercase;text-decoration: none;width: 260px;margin:
+              auto;border-radius: 5px;padding: 16px;">' . $email_text_button . '</a></td>
+      </tr>
+      <tr>
+          <td style="padding: 30px;" >
+              <span style="text-align: center;display: block; font-weight:bold; font-size:14px; text-decoration: none;">' . $email_description . '</span> <br />
+              <a rel="notrack" class="subscribe" href="' . $url . '" style="text-align: center;display: block;color: black; font-size: 12px; text-decoration: underline; margin: auto;">
+                 ' . $url . '
+              </a>
+          </td>
+      </tr>
+     
+      <tr><td style="text-align: left; height: 75px; line-height: 75px; width: 100%; vertical-align: middle; padding: 0 60px;"><div id="opt-in-footer" class="paint-area paint-area--text" contenteditable="true" style="display: inline-block; font-family: Ubuntu, Helvetica; text-align: left; margin-bottom: 24px; color: grey; line-height: normal;"><i class="medium-i">' . $email_description_footer . '</i></div></td></tr>
+    
+
+      <tr><td style="text-align: left; padding: 0 60px; height: 30px; line-height: 30px;"><div id="opt-in-signature-top" class="paint-area paint-area--text" contenteditable="true" style="font-family: Ubuntu, Helvetica; display: inline-block; text-align: left; color: grey; line-height: normal;">' . $email_footer . '</div></td></tr>
+      <tr><td style="text-align: left; padding: 0 60px; height: 30px; line-height: 30px;"><div id="opt-in-signature-bottom" class="paint-area paint-area--text" contenteditable="true" style="font-family: Ubuntu, Helvetica; display: inline-block; text-align: left; color: grey; line-height: normal;"><b class="medium-b">' . $email_owner . '</b></div></td></tr>
+      </tbody>
     </table>
 </div>';
 
@@ -934,4 +943,4 @@ function mailjet_theme($existing, $type, $theme, $path) {
       'template' => 'block--local-actions-block',
     ],
   ];
-} 
+}
