diff --git a/simplesamlphp_auth.module b/simplesamlphp_auth.module
index 6efa3d6..0eb09db 100644
--- a/simplesamlphp_auth.module
+++ b/simplesamlphp_auth.module
@@ -297,49 +297,58 @@ function simplesamlphp_auth_init() {
  * Implements hook_user_insert().
  */
 function simplesamlphp_auth_user_insert(&$edit, $account, $category = NULL) {
-  global $_simplesamlphp_auth_as;
-  global $_simplesamlphp_auth_saml_attributes;
-
-  if ($category = 'account') {
-    // If user registration has a valid session...
-    if ($_simplesamlphp_auth_as->isAuthenticated()) {
-      // Get name from default attributes.
-      try {
-        _simplesaml_auth_debug(t('Registering user [%acctname]', array('%acctname' => $account->name)));
-        $account->name = _simplesamlphp_auth_get_default_name($account->uid);
-      }
-      catch (Exception $e) {
-        $message = t('Username is missing.' . $e->getMessage());
-        drupal_set_message($message, "error");
-        watchdog('simplesamlphp', $message, WATCHDOG_CRITICAL);
-      }
-
-      db_update('users')
-        ->fields(array('name' => $account->name))
-        ->condition('uid', $account->uid)
-        ->execute();
 
-      _simplesaml_auth_debug(t('Updating username [%acctname]', array('%acctname' => $account->name)));
+  if (!_simplesamlphp_auth_isEnabled()) {
+    // Exit without initializing.
+    return;
+  }
+  else {
 
-      // Get mail from default attribute.
-      try {
-        $mail_address = _simplesamlphp_auth_get_mail();
-      }
-      catch (Exception $e)  {
-        $message = t('Email is missing.' . $e->getMessage());
-        drupal_set_message($message, "error");
-        watchdog('simplesamlphp', $message, WATCHDOG_CRITICAL);
-      }
+    global $_simplesamlphp_auth_as;
+    global $_simplesamlphp_auth_saml_attributes;
 
-      if (!empty($mail_address)) {
+    if ($category = 'account') {
+      // If user registration has a valid session...
+      if ($_simplesamlphp_auth_as->isAuthenticated()) {
+        // Get name from default attributes.
+        try {
+          _simplesaml_auth_debug(t('Registering user [%acctname]', array('%acctname' => $account->name)));
+          $account->name = _simplesamlphp_auth_get_default_name($account->uid);
+        }
+        catch (Exception $e) {
+          $message = t('Username is missing.' . $e->getMessage());
+          drupal_set_message($message, "error");
+          watchdog('simplesamlphp', $message, WATCHDOG_CRITICAL);
+        }
+  
         db_update('users')
-          ->fields(array('mail' => $mail_address))
+          ->fields(array('name' => $account->name))
           ->condition('uid', $account->uid)
           ->execute();
+  
+        _simplesaml_auth_debug(t('Updating username [%acctname]', array('%acctname' => $account->name)));
+  
+        // Get mail from default attribute.
+        try {
+          $mail_address = _simplesamlphp_auth_get_mail();
+        }
+        catch (Exception $e)  {
+          $message = t('Email is missing.' . $e->getMessage());
+          drupal_set_message($message, "error");
+          watchdog('simplesamlphp', $message, WATCHDOG_CRITICAL);
+        }
+  
+        if (!empty($mail_address)) {
+          db_update('users')
+            ->fields(array('mail' => $mail_address))
+            ->condition('uid', $account->uid)
+            ->execute();
+        }
+  
+        _simplesaml_auth_debug(t('Updating mail [%mailaddr]', array('%mailaddr' => $mail_address)));
       }
-
-      _simplesaml_auth_debug(t('Updating mail [%mailaddr]', array('%mailaddr' => $mail_address)));
     }
+
   }
 }
 
