diff --git a/supported/.DS_Store b/supported/.DS_Store
deleted file mode 100644
index 5008ddf..0000000
Binary files a/supported/.DS_Store and /dev/null differ
diff --git a/supported/content_profile.inc b/supported/content_profile.inc
index e046d2a..dbf3963 100644
--- a/supported/content_profile.inc
+++ b/supported/content_profile.inc
@@ -1,20 +1,26 @@
 <?php
+/**
+ * @file
+ * Content_profile.inc
+ */
 
 // Functionality depends on node_import and CCK.
 if (module_exists('node_import') && module_exists('content')) {
 
   // Load the required API files.
-  include_once('./'. drupal_get_path('module', 'node_import') . '/node_import.api.php');
-  include_once('./'. drupal_get_path('module', 'node_import') . '/node_import.inc');
+  include_once './' . drupal_get_path('module', 'node_import') . '/node_import.api.php';
+  include_once './' . drupal_get_path('module', 'node_import') . '/node_import.inc';
 
 
   /**
-   * Implementation of hook_user_import_form_field_match(). Add supported Content Profile fields into our dropdown list.
+   * Implements hook_user_import_form_field_match().
+   *
+   * Add supported Content Profile fields into our dropdown list.
    */
   function content_profile_user_import_form_field_match() {
     $options = array();
-		$options['content_profile'] = array();
-		$field_options = array();  
+    $options['content_profile'] = array();
+    $field_options = array();
     $contentprofile_types = content_profile_get_types();
 
     foreach ($contentprofile_types as $type => $data) {
@@ -22,24 +28,23 @@ if (module_exists('node_import') && module_exists('content')) {
 
       // Give fields a more descriptive title.
       foreach (array_keys($fields) as $key) {
-        if (strstr($key, 'cck:field_')) { 
-          $field_options["$type $key"] = t('Content Profile: (!type) !key ', array('!key' => $fields[$key]['title'], '!type' => $type)); 
+        if (strstr($key, 'cck:field_')) {
+          $field_options["$type $key"] = t('Content Profile: (!type) !key ', array('!key' => $fields[$key]['title'], '!type' => $type));
         }
       }
-			
-      // skip merge if there are no fields on the content type
+
+      // Skip merge if there are no fields on the content type.
       if (!empty($field_options)) {
         $options['content_profile'] = array_merge($options['content_profile'], $field_options);
       }
     }
-    
-    /* We do not support taxonomy yet */
 
+    // We do not support taxonomy yet.
     return $options;
   }
 
   /**
-   * Implementation of hook_user_import_form_update_user().
+   * Implements hook_user_import_form_update_user().
    */
   function content_profile_user_import_form_update_user() {
     $form['content_profile'] = array('title' => t('Content Profile'), 'description' => t('Affected: fields in Content Profile nodes.'));
@@ -47,34 +52,40 @@ if (module_exists('node_import') && module_exists('content')) {
   }
 
   /**
-   * Implementation of hook_user_import_data().
+   * Implements hook_user_import_data().
    */
   function content_profile_user_import_data($settings, $update_setting, $column_settings, $module, $field_id, $data, $column_id) {
-    if ($module != 'content_profile') return;
+    if ($module != 'content_profile') {
+      return;
+    }
     return trim($data[$column_id]);
   }
 
   /**
-   * Implementation of hook_user_import_after_save().
+   * Implements hook_user_import_after_save().
    */
   function content_profile_user_import_after_save($settings, $account, $password, $fields, $updated, $update_setting_per_module) {
- 
-    if (!isset($fields['content_profile']) || !is_array($fields['content_profile'])) return;
-    
-    // check if it's an existing user and if content profile is to be updated 
-    if ($updated && $update_setting_per_module['content_profile'] == UPDATE_NONE) return;
 
-    // arrange values by content type    
+    if (!isset($fields['content_profile']) || !is_array($fields['content_profile'])) {
+      return;
+    }
+
+    // Check if it's an existing user and if content profile is to be updated.
+    if ($updated && $update_setting_per_module['content_profile'] == UPDATE_NONE) {
+      return;
+    }
+
+    // Arrange values by content type.
     foreach ($fields['content_profile'] as $column_id => $column_data) {
       if (!empty($column_data)) {
         $keys = explode(' ', $column_id);
         $contentprofile[$keys[0]][$keys[1]] = $column_data;
       }
-    } 
+    }
 
     $contentprofile_types = content_profile_get_types();
-    
-    // process each $content profile
+
+    // Process each $content profile.
     foreach ($contentprofile_types as $type => $configuration) {
       content_profile_user_import_node($type, $contentprofile, $account, $fields, $updated, $update_setting_per_module['content_profile']);
     }
@@ -83,16 +94,18 @@ if (module_exists('node_import') && module_exists('content')) {
   }
 
   /**
-   *  callback to create or update a node if appropriate
+   * Callback to create or update a node if appropriate.
    */
   function content_profile_user_import_node($type, $content_profile, $account, $fields, $updated, $update_setting) {
-  
-    if (empty($content_profile[$type])) return;  // pass only those, which are used
- 
-    $errors = array();      
+
+    // Pass only those, which are used.
+    if (empty($content_profile[$type])) {
+      return;
+    }
+    $errors = array();
     $title_empty = time();
 
-    if ($updated) { 
+    if ($updated) {
       $node = node_load(array('type' => $type, 'uid' => $account->uid));
     }
 
@@ -100,14 +113,14 @@ if (module_exists('node_import') && module_exists('content')) {
       $node = new StdClass();
       $node->type = $type;
       $node->status = 1;
-      $node->title = $title_empty; 
-    } 
+      $node->title = $title_empty;
+    }
 
-    // Assign the mapped fields to the $node.    
+    // Assign the mapped fields to the $node.
     foreach ($content_profile[$type] as $column_id => $column_data) {
-	
-    	$field_data = explode(':', $column_id);
-    	$field_name = !empty($field_data[1]) ? $field_data[1] : $column_id; 
+
+      $field_data = explode(':', $column_id);
+      $field_name = !empty($field_data[1]) ? $field_data[1] : $column_id;
       $field_key = !empty($field_data[2]) ? $field_data[2] : 'value';
       $field_value = array(0 => array($field_key => $column_data[0]));
 
@@ -118,16 +131,16 @@ if (module_exists('node_import') && module_exists('content')) {
 
         $current_content = content_format($field_name, $node->{$field_name}[0], 'default', $node);
 
-        if (empty($current_content) && !empty($column_data[0])) { 
-					$node->{$field_name} = $field_value;
+        if (empty($current_content) && !empty($column_data[0])) {
+          $node->{$field_name} = $field_value;
         }
       }
       elseif ($updated && $update_setting == UPDATE_REPLACE) {
-        $node->{$field_name} = $field_value; 
-      }  
+        $node->{$field_name} = $field_value;
+      }
     }
-    
-		// not actually checking for errors at the moment, but lete's leave this in for when we do
+
+    // Not checking for errors, but let's leave this in for when we do.
     if (empty($errors)) {
       $node->uid = $account->uid;
       $node->name = $account->name;
@@ -136,26 +149,25 @@ if (module_exists('node_import') && module_exists('content')) {
       if (!isset($node->title) || empty($node->title) || $node->title == $title_empty) {
         $node->title = $node->name;
       }
-      
-      $node = node_submit($node); 
-      
-      // make sure author is not changed when submited (hapens if existing node)
+
+      $node = node_submit($node);
+
+      // Author is not changed when submitted happens if existing node.
       $node->uid = $account->uid;
       $node->name = $account->name;
-       
+
       node_save($node);
 
       if (!$node->nid) {
         drupal_set_message(t('Unknown error on saving the node: %node_data! Check watchdog logs for details.', array('%node_data' => "$node->title ($node->type)")), 'error');
       }
-      
-    } else {
-    /**
-     * @todo report errors
-     */
-    } 
-  }
 
-} else {
+    }
+    else {
+      // @todo report errors
+    }
+  }
+}
+else {
   drupal_set_message(t('Please enable %module module!', array('%module' => 'node_import')));
 }
diff --git a/supported/location.inc b/supported/location.inc
index 5adc34c..d01cf67 100644
--- a/supported/location.inc
+++ b/supported/location.inc
@@ -1,11 +1,16 @@
 <?php
-// $Id$
+/**
+ * @file
+ * Location.inc
+ */
 
 // Functionality depends on User Location.
 if (module_exists('location_user')) {
 
   /**
-   * Implementation of hook_user_import_form_field_match(). Add supported Location fields into our dropdown list.
+   * Implements hook_user_import_form_field_match().
+   *
+   * Add supported Location fields into our dropdown list.
    */
   function location_user_import_form_field_match() {
     $options = array();
@@ -14,7 +19,7 @@ if (module_exists('location_user')) {
   }
 
   /**
-   * Implementation of hook_user_import_form_update_user().
+   * Implements hook_user_import_form_update_user().
    */
   function location_user_import_form_update_user() {
     $form['location'] = array(
@@ -25,7 +30,7 @@ if (module_exists('location_user')) {
   }
 
   /**
-   * Implementation of hook_user_import_data().
+   * Implements hook_user_import_data().
    */
   function location_user_import_data($settings, $update_setting, $column_settings, $module, $field_id, $data, $column_id) {
     if ($module != 'location') {
@@ -79,23 +84,23 @@ if (module_exists('location_user')) {
   }
 
   /**
-   * Implementation of hook_user_import_after_save().
+   * Implements hook_user_import_after_save().
    */
   function location_user_import_after_save($settings, $account, $password, $fields, $updated, $update_setting_per_module) {
     if (!is_array($fields['location'])) {
       return;
     }
-    // check if it's an existing user and if location is to be updated
+    // Check if it's an existing user and if location is to be updated.
     if ($updated && $update_setting_per_module['location'] == UPDATE_NONE) {
       return;
     }
-    // Arrange values for location array
+    // Arrange values for location array.
     $location = array();
 
     foreach ($fields['location'] as $column_id => $column_data) {
       $location[0][$column_id] = $column_data[0];
-    } 
-    // Merge defaults in
+    }
+    // Merge defaults in.
     $dummy = array();
     $defaults = location_invoke_locationapi($dummy, 'defaults');
 
@@ -108,6 +113,4 @@ if (module_exists('location_user')) {
     location_save_locations($location, array('uid' => $account->uid));
     return;
   }
-
 }
-
diff --git a/supported/profile.inc b/supported/profile.inc
index 55338fa..b01b8ca 100644
--- a/supported/profile.inc
+++ b/supported/profile.inc
@@ -1,7 +1,11 @@
 <?php
+/**
+ * @file
+ * Profile.inc
+ */
 
 /**
- * Implementation of hook_user_import_form_field_match().
+ * Implements hook_user_import_form_field_match().
  */
 function profile_user_import_form_field_match() {
   module_load_include('inc', 'user_import', 'user_import.admin');
@@ -11,7 +15,7 @@ function profile_user_import_form_field_match() {
 }
 
 /**
- * Implementation of hook_user_import_form_update_user().
+ * Implements hook_user_import_form_update_user().
  */
 function profile_user_import_form_update_user() {
   $form['profile'] = array('title' => t('Profile'), 'description' => t('Affected: Profile fields.'));
@@ -19,93 +23,100 @@ function profile_user_import_form_update_user() {
 }
 
 /**
- * Implementation of hook_user_import_data().
+ * Implements hook_user_import_data().
  */
 function profile_user_import_data($settings, $update_setting, $column_settings, $module, $field_id, $data, $column_id) {
 
-  if ($module!= 'profile') return;
+  if ($module != 'profile') {
+    return;
+  }
   return trim($data[$column_id]);
 }
 
 /**
- * Implementation of hook_user_import_after_save().
+ * Implements hook_user_import_after_save().
  */
 function profile_user_import_after_save($settings, $account, $password, $fields, $updated, $update_setting_per_module) {
 
-  // get all fields
+  // Get all fields.
   $profile_fields = profile_get_fields();
   $data = $old_data = unserialize($account->data);
 
   foreach ($profile_fields as $field) {
     profile_user_import_save_profile($field, $account->uid, $fields['profile'][$field->fid][0], $updated, $update_setting_per_module['profile'], $data);
   }
-  
-  // data column in the user table needs to be updated
-  if ($data != $old_data) {   
+
+  // Data column in the user table needs to be updated.
+  if ($data != $old_data) {
     db_query("UPDATE {users} SET data = '%s' WHERE uid = %d", serialize($data), $account->uid);
-  } 
+  }
 
   return;
 }
 
 
-function profile_user_import_save_profile($field, $uid, $value, $updated, $update_setting, &$data) {   
+function profile_user_import_save_profile($field, $uid, $value, $updated, $update_setting, &$data) {
 
-  // when the profile field is displayed on the registration form an empty value is automatically saved by the Profile module
+  // When the profile field is displayed on the registration form an empty
+  // value is automatically saved by the Profile module.
   $exists = db_result(db_query_range("SELECT value FROM {profile_values} WHERE fid = %d AND uid = %d", $field->fid, $uid, 0, 1));
 
-	user_import_profile_date($value, $field->type);
+  user_import_profile_date($value, $field->type);
+
+  if ($updated) {
 
-  if ($updated) { 
- 
     switch ($update_setting) {
-      case UPDATE_NONE: 
+      case UPDATE_NONE:
         return;
-        
+
       case UPDATE_ADD:
-        if (empty($value) || (!empty($exists) && $exists != '')) return;
+        if (empty($value) || (!empty($exists) && $exists != '')) {
+          return;
+        }
 
       case UPDATE_REPLACE:
 
         if (empty($value) && $update_setting == UPDATE_REPLACE) {
-          
+
           db_query("DELETE FROM {profile_values} WHERE fid = %d AND uid = %d", $field->fid, $uid);
           unset($data[$field->name]);
           return;
         }
 
-        if ((empty($exists) && $exists != '') || $exists === FALSE) { 
- 	
+        if ((empty($exists) && $exists != '') || $exists === FALSE) {
+
           db_query("INSERT INTO {profile_values} (fid,uid,value) VALUES(%d,%d,'%s')", $field->fid, $uid, $value);
         }
         else {
-          db_query("UPDATE {profile_values} SET value = '%s' WHERE fid = %d AND uid = %d", $value, $field->fid, $uid);  
+          db_query("UPDATE {profile_values} SET value = '%s' WHERE fid = %d AND uid = %d", $value, $field->fid, $uid);
         }
-        
-        $data[$field->name] = $value; 
+
+        $data[$field->name] = $value;
         return;
-    } 
+    }
 
   }
   else {
 
-    if (empty($value)) return;
- 
-    if ((empty($exists) && $exists != '') || $exists === FALSE) {  
+    if (empty($value)) {
+      return;
+    }
+
+    if ((empty($exists) && $exists != '') || $exists === FALSE) {
       db_query("INSERT INTO {profile_values} (fid,uid,value) VALUES(%d,%d,'%s')", $field->fid, $uid, $value);
     }
-    else {  
-     db_query("UPDATE {profile_values} SET value = '%s' WHERE fid = %d AND uid = %d", $value, $field->fid, $uid);
+    else {
+      db_query("UPDATE {profile_values} SET value = '%s' WHERE fid = %d AND uid = %d", $value, $field->fid, $uid);
       $data[$field->name] = $value;
     }
   }
 
-  return;   
+  return;
 }
 
 
 /**
- * 
+ * Function profile_get_fields.
  */
 function profile_get_fields() {
 
@@ -124,44 +135,45 @@ function profile_get_fields() {
 }
 
 /**
- * Convert date into format that Profile module expects:
+ * Convert date into format that Profile module expects.
+ *
  * a:3:{s:5:"month";s:1:"1";s:3:"day";s:1:"1";s:4:"year";s:4:"1976";}
  */
 function user_import_profile_date(&$value, $field_type) {
-	
+
   if ($field_type != "date" || empty($value)) {
-	  return;
-	}
-	
-	$date = explode('/', $value);
-	
-	if (!is_array($date)) {
-		return;
-	}
-	
-	// Get seleceted format.
-	$date_format = variable_get('user_import_profile_date_format', 'MM/DD/YYYY');
-	
-	if ($date_format == 'MM/DD/YYYY') {
-	  list($month, $day, $year) = explode('/', $value);
-	}
-	else if ($date_format == 'DD/MM/YYYY') {
-	  list($day, $month, $year) = explode('/', $value);
-	}
-	else if ($date_format == 'YYYY/MM/DD') {
-	  list($year, $month, $day) = explode('/', $value);
-	}
-	else if ($date_format == 'YYYY/DD/MM') {
-	  list($year, $day, $month) = explode('/', $value);
-	}
+    return;
+  }
 
-	// Leading zeros cause a problem so remove them.
-	if (substr($day, 0, 1) == '0') {
-	  $day = substr($day, 1, 1);
-	}
-	if (substr($month, 0, 1) == '0') {
-	  $month = substr($month, 1, 1);
-	}
+  $date = explode('/', $value);
 
-	$value = serialize(array('month' => $month, 'day' => $day, 'year' => $year));
-}
\ No newline at end of file
+  if (!is_array($date)) {
+    return;
+  }
+
+  // Get seleceted format.
+  $date_format = variable_get('user_import_profile_date_format', 'MM/DD/YYYY');
+
+  if ($date_format == 'MM/DD/YYYY') {
+    list($month, $day, $year) = explode('/', $value);
+  }
+  elseif ($date_format == 'DD/MM/YYYY') {
+    list($day, $month, $year) = explode('/', $value);
+  }
+  elseif ($date_format == 'YYYY/MM/DD') {
+    list($year, $month, $day) = explode('/', $value);
+  }
+  elseif ($date_format == 'YYYY/DD/MM') {
+    list($year, $day, $month) = explode('/', $value);
+  }
+
+  // Leading zeros cause a problem so remove them.
+  if (substr($day, 0, 1) == '0') {
+    $day = substr($day, 1, 1);
+  }
+  if (substr($month, 0, 1) == '0') {
+    $month = substr($month, 1, 1);
+  }
+
+  $value = serialize(array('month' => $month, 'day' => $day, 'year' => $year));
+}
diff --git a/supported/subscribed.inc b/supported/subscribed.inc
index 5bf372d..2eb44e3 100644
--- a/supported/subscribed.inc
+++ b/supported/subscribed.inc
@@ -1,45 +1,51 @@
 <?php
+/**
+ * @file
+ * Subscribed.inc
+ */
 
 /**
- * Implementation of hook_user_import_form_fieldsets().
+ * Implements hook_user_import_form_fieldsets().
  */
 function subscribed_user_import_form_fieldset($import, $collapsed) {
 
- if (module_exists('publication') && module_exists('schedule')) {
+  if (module_exists('publication') && module_exists('schedule')) {
 
     $publications = publication_select_publications('enewsletter');
-    if (empty($publications)) return;
+    if (empty($publications)) {
+      return;
+    }
 
     $form['subscribed'] = array(
-        '#type' => 'fieldset',
-        '#title' => t('Subscriptions'),
-        '#collapsible' => TRUE,
-        '#collapsed' => $collapsed,
-        '#tree' => TRUE,
+      '#type' => 'fieldset',
+      '#title' => t('Subscriptions'),
+      '#collapsible' => TRUE,
+      '#collapsed' => $collapsed,
+      '#tree' => TRUE,
     );
-    
+
     foreach ($publications as $publication) {
-    
+
       $type = $publication->type;
-      
+
       $form['subscribed'][$type] = array(
-          '#type' => 'fieldset',
-          '#title' => check_plain($type),
+        '#type' => 'fieldset',
+        '#title' => check_plain($type),
       );
-      
+
     }
-    
+
     reset($publications);
     $subscribed = $import['options']['subscribed'];
- 
+
     foreach ($publications as $publication) {
-      
+
       $options = array();
       $schedules = schedule_select_schedules($type, $publication->publication_id);
       $options[0] = t('No Subscription');
-      
-      foreach ($schedules as $schedule) {                     
-        $options[ $schedule['schedule_id'] ] = $schedule['schedule_title'];
+
+      foreach ($schedules as $schedule) {
+        $options[$schedule['schedule_id']] = $schedule['schedule_title'];
       }
 
       $subscription_default = empty($subscribed[$type][$publication->publication_id]) ? 0 : $subscribed[$type][$publication->publication_id][0];
@@ -51,15 +57,15 @@ function subscribed_user_import_form_fieldset($import, $collapsed) {
         '#options' => $options,
         '#description' => check_plain($publication->description),
       );
-      
+
     }
   }
-  
+
   return $form;
 }
 
 /**
- * Implementation of hook_user_import_form_update_user().
+ * Implements hook_user_import_form_update_user().
  */
 function subscribed_user_import_form_update_user() {
   $form['subscribed'] = array('title' => t('Subscribed'), 'description' => t('Affected: subscriptions.'));
@@ -67,35 +73,37 @@ function subscribed_user_import_form_update_user() {
 }
 
 /**
- * Implementation of hook_user_import_after_save().
+ * Implements hook_user_import_after_save().
  */
 function subscribed_user_import_after_save($settings, $account, $password, $fields, $updated) {
-/**
- * @todo change to new update architecture
- */   
-  if (!module_exists('publication') || !module_exists('schedule') || !module_exists('identity_hash') || empty($settings['options']['subscribed'])) return;
-  
+  // @todo change to new update architecture
+  if (!module_exists('publication') || !module_exists('schedule') || !module_exists('identity_hash') || empty($settings['options']['subscribed'])) {
+    return;
+  }
+
   $subscribed_settings = $settings['options']['subscribed'];
   $uid = $account->uid;
 
-  if (is_array($subscribed_settings)) {  
-  
-    foreach($subscribed_settings as $type => $type_subscriptions) {
+  if (is_array($subscribed_settings)) {
 
-      $subscriptions = $type_subscriptions; 
+    foreach ($subscribed_settings as $type => $type_subscriptions) {
 
-      foreach($type_subscriptions as $publication_id => $schedule) {
-        if (empty($schedule[0])) unset($subscriptions[$publication_id]);
+      $subscriptions = $type_subscriptions;
+
+      foreach ($type_subscriptions as $publication_id => $schedule) {
+        if (empty($schedule[0])) {
+          unset($subscriptions[$publication_id]);
+        }
       }
 
       $publications = publication_select_publications_and_terms($type);
 
       if (!empty($publications) && !empty($subscriptions)) {
         subscribed_set_subscriptions($type, $uid, $publications, $subscriptions);
-        subscribed_set_subscriptions_terms($type, $uid, $publications, $subscriptions); 
+        subscribed_set_subscriptions_terms($type, $uid, $publications, $subscriptions);
         identity_hash_set_hash($uid);
       }
     }
   }
   return;
-}
\ No newline at end of file
+}
diff --git a/supported/user.inc b/supported/user.inc
index a5d9765..3431016 100644
--- a/supported/user.inc
+++ b/supported/user.inc
@@ -1,27 +1,28 @@
 <?php
-
 /**
- * @todo move contact options to separate contact.inc
+ * @file
+ * User.inc
  */
 
+// @todo move contact options to separate contact.inc
 /**
- * Implementation of hook_user_import_form_field_match().
+ * Implements hook_user_import_form_field_match().
  */
 function user_user_import_form_field_match() {
 
   $options = array();
   $options['user']['email'] = t('Email Address*');
-  $options['user']['password'] = t('Password'); 
+  $options['user']['password'] = t('Password');
   $options['user']['roles'] = t('Roles');
-	// $options['user']['username'] = t('Username');
-	// $options['user']['uid'] = t('UID');
-	// $options['user']['modified'] = t('Modified');
+  // $options['user']['username'] = t('Username');
+  // $options['user']['uid'] = t('UID');
+  // $options['user']['modified'] = t('Modified');
   return $options;
 }
 
 
 /**
- * Implementation of hook_user_import_form_fieldsets().
+ * Implements hook_user_import_form_fieldsets().
  */
 function user_user_import_form_fieldset($import, $collapsed) {
 
@@ -33,25 +34,35 @@ function user_user_import_form_fieldset($import, $collapsed) {
 }
 
 /**
- * Implementation of hook_user_import_form_update_user().
+ * Implements hook_user_import_form_update_user().
  */
 function user_user_import_form_update_user() {
   $form['roles'] = array('title' => t('Roles'), 'description' => t('Affected: roles assigned to user.'));
-  $form['password'] = array('title' => t('Password'), 'description' => t('Affected: password.'), 'exclude_add' => TRUE);
-  $form['contact'] = array('title' => t('Contact'), 'description' => t('Affected: user contact option.'), 'exclude_add' => TRUE);
+  $form['password'] = array(
+    'title' => t('Password'),
+    'description' => t('Affected: password.'),
+    'exclude_add' => TRUE,
+  );
+  $form['contact'] = array(
+    'title' => t('Contact'),
+    'description' => t('Affected: user contact option.'),
+    'exclude_add' => TRUE,
+  );
   return $form;
 }
 
 /**
- * Implementation of hook_user_import_data().
- */  
+ * Implements hook_user_import_data().
+ */
 function user_user_import_data($settings, $update_setting, $column_settings, $module, $field_id, $data, $column_id) {
 
-  if ($module != 'user') return;
+  if ($module != 'user') {
+    return;
+  }
 
   if ($field_id == 'email') {
     $value = trim($data[$column_id]);
-  
+
     _user_import_validate_email($value, $update_setting);
   }
 
@@ -67,54 +78,54 @@ function user_user_import_data($settings, $update_setting, $column_settings, $mo
 }
 
 /**
- * Implementation of hook_user_import_pre_save().
+ * Implements hook_user_import_pre_save().
  */
 function user_user_import_pre_save($settings, $account, $fields, $errors, $update_setting_per_module) {
- 
+
   $account_add['mail'] = $fields['user']['email'][0];
 
-  if (!empty($account['uid'])) {     
-  
-    // update roles
+  if (!empty($account['uid'])) {
+
+    // Update roles.
     switch ($update_setting_per_module['roles']) {
       case UPDATE_ADD:
-        // include currently assigned roles
+        // Include currently assigned roles.
         foreach ($account['roles'] as $rid => $role_name) {
           $account_add['roles'][$rid] = $rid;
         }
-      
+
       case UPDATE_REPLACE:
-        // update roles
+        // Update roles.
         if (!isset($account_add['roles'])) {
-					$account_add['roles'] = array();
-				}
+          $account_add['roles'] = array();
+        }
 
         foreach ($settings['roles'] as $rid => $role_set) {
           if (!empty($role_set)) {
-						$account_add['roles'][$rid] = $rid;	
-					} 
+            $account_add['roles'][$rid] = $rid;
+          }
         }
 
         break;
     }
-    
-		// update password
-		if ($update_setting_per_module['password'] == UPDATE_REPLACE) {
-    	$account_add['pass'] = (empty($fields['user']['password'][0])) ? user_password() : $fields['user']['password'][0];
-		}
-		else {
-			$account_add['pass'] = "";
-		}
-    
-		// update contact
-		if ($update_setting_per_module['contact'] == UPDATE_REPLACE) {
-			$account_add['contact'] = $settings['contact'];
-		} 
-		else {
-			$account_add['contact'] = isset($account['contact']) ? $account['contact'] : '';
-		}
 
-  } 
+    // Update password.
+    if ($update_setting_per_module['password'] == UPDATE_REPLACE) {
+      $account_add['pass'] = (empty($fields['user']['password'][0])) ? user_password() : $fields['user']['password'][0];
+    }
+    else {
+      $account_add['pass'] = "";
+    }
+
+    // Update contact.
+    if ($update_setting_per_module['contact'] == UPDATE_REPLACE) {
+      $account_add['contact'] = $settings['contact'];
+    }
+    else {
+      $account_add['contact'] = isset($account['contact']) ? $account['contact'] : '';
+    }
+
+  }
   else {
 
     $account_add['timezone'] = '-18000';
@@ -126,112 +137,120 @@ function user_user_import_pre_save($settings, $account, $fields, $errors, $updat
       $account_add['access'] = time();
       $account_add['login'] = time();
     }
-  
-    // add selected roles
+
+    // Add selected roles.
     foreach ($settings['roles'] as $rid => $role_set) {
-      if (!empty($role_set)) $account_add['roles'][$rid] = $rid;
+      if (!empty($role_set)) {
+        $account_add['roles'][$rid] = $rid;
+      }
     }
   }
-  
+
   return $account_add;
 }
 
 /**
- * Implementation of hook_user_import_after_save().
+ * Implements hook_user_import_after_save().
  */
 function user_user_import_after_save($settings, $account, $password, $fields, $updated, $update_setting_per_module) {
-  /**
-   * @todo change hook_user_import_after_save() so that all changes to data are returned and saved in one hit
-   */
+
+  // @todo change hook_user_import_after_save() so that all changes to
+  // data are returned and saved in one hit.
   $roles = isset($fields['user']['roles']) ? $fields['user']['roles'] : array();
 
-	user_user_import_after_save_role($account, $settings['roles_new'], $account->roles, $roles);
+  user_user_import_after_save_role($account, $settings['roles_new'], $account->roles, $roles);
   return;
 }
 
-function user_user_import_edit_roles_fields(&$form, $import, $collapsed) { 
-  $roles = array();    
+function user_user_import_edit_roles_fields(&$form, $import, $collapsed) {
+  $roles = array();
   $roles_data = user_roles();
 
-  // remove 'anonymous user' option
-  while (list ($rid, $role_name) = each ($roles_data)) {
-    if ($role_name != 'anonymous user' && $role_name != 'authenticated user') $roles[$rid] = $role_name;
+  // Remove 'anonymous user' option.
+  while (list($rid, $role_name) = each($roles_data)) {
+    if ($role_name != 'anonymous user' && $role_name != 'authenticated user') {
+      $roles[$rid] = $role_name;
+    }
   }
-  
-  // roles selected
-  if ( !empty($import['roles']) ) {
+
+  // Roles selected.
+  if (!empty($import['roles'])) {
     foreach ($import['roles'] as $rid) {
-      if ($rid != 0) $roles_selected[] = $rid;
-    } 
+      if ($rid != 0) {
+        $roles_selected[] = $rid;
+      }
+    }
+  }
+
+  if (empty($roles_selected)) {
+    $roles_selected[] = 2;
   }
-  
-  if (empty($roles_selected)) $roles_selected[] = 2; 
 
   $form['role_selection'] = array(
-      '#type' => 'fieldset',
-      '#title' => t('Role Assign'),
-      '#weight' => -80,
-      '#collapsible' => TRUE,
-      '#collapsed' => $collapsed,
+    '#type' => 'fieldset',
+    '#title' => t('Role Assign'),
+    '#weight' => -80,
+    '#collapsible' => TRUE,
+    '#collapsed' => $collapsed,
   );
-  
+
   $form['role_selection']['roles'] = array(
-      '#title' => t('Assign Role(s) To All Users'), 
-      '#type' => 'checkboxes',
-      '#options' => $roles,
-      '#default_value' => $roles_selected,
-      '#description' => t("Select which role(s) all imported users should be assigned. The role 'authenticated user' is assigned automatically."),
+    '#title' => t('Assign Role(s) To All Users'),
+    '#type' => 'checkboxes',
+    '#options' => $roles,
+    '#default_value' => $roles_selected,
+    '#description' => t("Select which role(s) all imported users should be assigned. The role 'authenticated user' is assigned automatically."),
   );
 
   $form['role_selection']['roles_new'] = array(
-      '#type' => 'checkbox',
-      '#title' => t('Add New Roles'),
-      '#default_value' => isset($import['roles_new']) ? $import['roles_new'] : 0,
-      '#description' => t('Create imported role(s) that are not found and assign it to the user, in addition to any role(s) selected above. Warning: incorrect roles will be created if the incoming data includes typos.'),
+    '#type' => 'checkbox',
+    '#title' => t('Add New Roles'),
+    '#default_value' => isset($import['roles_new']) ? $import['roles_new'] : 0,
+    '#description' => t('Create imported role(s) that are not found and assign it to the user, in addition to any role(s) selected above. Warning: incorrect roles will be created if the incoming data includes typos.'),
   );
-  
+
   return;
 }
 
-function user_user_import_edit_email_fields(&$form, $import, $collapsed) { 
+function user_user_import_edit_email_fields(&$form, $import, $collapsed) {
 
-    $form['email_message'] = array(
-        '#type' => 'fieldset',
-        '#title' => t('Email Message'),
-        '#description' => t('Welcome message to be sent to imported users. Leave blank to use the default !message. If an existing user account is updated no welcome email will be sent to that user. <strong>Note - if "Activate Accounts" option is enabled !login_url (one time login) will not work.</strong>', array('!message' => l('message', 'admin/user/settings'))),
-        '#collapsible' => TRUE,
-        '#collapsed' => $collapsed,
-    );
+  $form['email_message'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Email Message'),
+    '#description' => t('Welcome message to be sent to imported users. Leave blank to use the default !message. If an existing user account is updated no welcome email will be sent to that user. <strong>Note - if "Activate Accounts" option is enabled !login_url (one time login) will not work.</strong>', array('!message' => l('message', 'admin/user/settings'))),
+    '#collapsible' => TRUE,
+    '#collapsed' => $collapsed,
+  );
 
-    $form['email_message']['subject'] = array(
-      '#type' => 'textfield',
-      '#title' => t('Message Subject'),
-      '#default_value' => isset($import['subject']) ? $import['subject'] : '',
-      '#description' => t('Customize the subject of the welcome e-mail, which is sent to imported members.') .' '. t('Available variables are:') .' !username, !site, !password, !uri, !uri_brief, !mailto, !date, !login_uri, !edit_uri, !login_url.',
-    ); 
-    
-    $form['email_message']['message'] = array(
-      '#type' => 'textarea',
-      '#title' => t('Message'),
-      '#default_value' => isset($import['message']) ? $import['message'] : '',
-      '#description' => t('Customize the body of the welcome e-mail, which is sent to imported members.') .' '. t('Available variables are:') .' !username, !site, !password, !uri, !uri_brief, !mailto, !login_uri, !edit_uri, !login_url.',
-    ); 
-    
-    $form['email_message']['message_format'] = array(
-      '#type' => 'radios',
-      '#title' => t('Email Format'),
-      '#default_value' => isset($import['message_format']) ? $import['message_format'] : 0,
-      '#options' => array(t('Plain Text'), t('HTML')),
-    );
-    
-    $form['email_message']['message_css'] = array(
-      '#type' => 'textarea',
-      '#title' => t('CSS'),
-      '#default_value' => isset($import['message_css']) ? $import['message_css'] : '',
-      '#description' => t('Use if sending HTML formated email.'),
-    );
-    
-    return;
+  $form['email_message']['subject'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Message Subject'),
+    '#default_value' => isset($import['subject']) ? $import['subject'] : '',
+    '#description' => t('Customize the subject of the welcome e-mail, which is sent to imported members.') . ' ' . t('Available variables are:') . ' !username, !site, !password, !uri, !uri_brief, !mailto, !date, !login_uri, !edit_uri, !login_url.',
+  );
+
+  $form['email_message']['message'] = array(
+    '#type' => 'textarea',
+    '#title' => t('Message'),
+    '#default_value' => isset($import['message']) ? $import['message'] : '',
+    '#description' => t('Customize the body of the welcome e-mail, which is sent to imported members.') . ' ' . t('Available variables are:') . ' !username, !site, !password, !uri, !uri_brief, !mailto, !login_uri, !edit_uri, !login_url.',
+  );
+
+  $form['email_message']['message_format'] = array(
+    '#type' => 'radios',
+    '#title' => t('Email Format'),
+    '#default_value' => isset($import['message_format']) ? $import['message_format'] : 0,
+    '#options' => array(t('Plain Text'), t('HTML')),
+  );
+
+  $form['email_message']['message_css'] = array(
+    '#type' => 'textarea',
+    '#title' => t('CSS'),
+    '#default_value' => isset($import['message_css']) ? $import['message_css'] : '',
+    '#description' => t('Use if sending HTML formated email.'),
+  );
+
+  return;
 }
 
 function _user_import_validate_email($email = NULL, $duplicates_allowed = FALSE) {
@@ -253,34 +272,36 @@ function _user_import_validate_email($email = NULL, $duplicates_allowed = FALSE)
 function user_user_import_roles_data($data, $new_roles_allowed) {
   $roles = array();
 
-  if (empty($data)) return;
-  $values = explode( ',', $data);
-  
-  // check if any roles are specified that don't already exist
+  if (empty($data)) {
+    return;
+  }
+  $values = explode(',', $data);
+
+  // Check if any roles are specified that don't already exist.
   $existing_roles = user_roles();
- 
-  foreach($values as $piece) {
+
+  foreach ($values as $piece) {
     $role = trim($piece);
     $unrecognised = array();
 
-		if (!empty($role)) {
-	    // only add if role is recognized or adding new roles is allowed
-	    if (empty($new_roles_allowed) && !array_search($role, $existing_roles)) {
-		  	$unrecognised[] = $role;
-	    }
-	    else {
-		  	$roles[] = $role;
-	    }
-		}
+    if (!empty($role)) {
+      // Only add if role is recognized or adding new roles is allowed.
+      if (empty($new_roles_allowed) && !array_search($role, $existing_roles)) {
+        $unrecognised[] = $role;
+      }
+      else {
+        $roles[] = $role;
+      }
+    }
 
   }
-  
+
   if (!empty($unrecognised)) {
-		user_import_errors(t('The following unrecognised roles were specified: ') . implode(',', $unrecognised));
+    user_import_errors(t('The following unrecognised roles were specified: ') . implode(',', $unrecognised));
   }
-  
-  return $roles;	
-} 
+
+  return $roles;
+}
 
 /**
  * Return an existing user ID, if present, for a given email.
@@ -293,39 +314,39 @@ function _user_import_existing_uid($email) {
 function user_user_import_after_save_role($account, $new_roles_allowed, $account_roles, $roles) {
 
   $existing_roles = user_roles();
-  
-  // if roles were specified, add to existing roles
+
+  // If roles were specified, add to existing roles.
   $assign_roles = array();
 
   if (is_array($roles) && !empty($roles)) {
 
-		foreach ($roles as $role) { 
+    foreach ($roles as $role) {
 
-	    if (!empty($role)) {
-			  $key = array_search($role, $existing_roles);
-			  if (!empty($new_roles_allowed) && empty($key)) {
-				  db_query("INSERT INTO {role} (name) VALUES ('%s')", $role);
-		      $key = db_result(db_query("SELECT rid FROM {role} WHERE name = '%s' LIMIT 1", $role));
-					$existing_roles[$key] = $role;
-			  }
+      if (!empty($role)) {
+        $key = array_search($role, $existing_roles);
+        if (!empty($new_roles_allowed) && empty($key)) {
+          db_query("INSERT INTO {role} (name) VALUES ('%s')", $role);
+          $key = db_result(db_query("SELECT rid FROM {role} WHERE name = '%s' LIMIT 1", $role));
+          $existing_roles[$key] = $role;
+        }
 
-			  $assign_roles[$key] = $role;
-			}
-		}
-	
-		$need_update = FALSE;
+        $assign_roles[$key] = $role;
+      }
+    }
 
- 	  foreach ($assign_roles as $key => $role) {
-		  if (!isset($account_roles[$key])) {
-		    $need_update = TRUE;
-		    $account_roles[$key] = $role;
-		  }
- 	  }
-	
-		if ($need_update) {
-			
-			user_save($account, array('roles' => $account_roles));
-	  }  
+    $need_update = FALSE;
+
+    foreach ($assign_roles as $key => $role) {
+      if (!isset($account_roles[$key])) {
+        $need_update = TRUE;
+        $account_roles[$key] = $role;
+      }
+    }
+
+    if ($need_update) {
+
+      user_save($account, array('roles' => $account_roles));
+    }
   }
 
   return;
diff --git a/supported/user_import.inc b/supported/user_import.inc
index bc0b9ed..e1f9b2c 100644
--- a/supported/user_import.inc
+++ b/supported/user_import.inc
@@ -1,8 +1,13 @@
 <?php
+/**
+ * @file
+ * User_import.inc
+ */
 
 /**
- * Implementation of hook_user_import_form_fieldsets().
- * Add fieldsets to an import settings form. 
+ * Implements hook_user_import_form_fieldsets().
+ *
+ * Add fieldsets to an import settings form.
  */
 function user_import_user_import_form_fieldset($import, $collapsed) {
 
@@ -10,252 +15,259 @@ function user_import_user_import_form_fieldset($import, $collapsed) {
   _user_import_edit_template_fields($form, $import);
   _user_import_edit_settings_fields($form, $import, $collapsed);
   _user_import_edit_remove_fields($form, $import);
-  
+
   return $form;
 }
- 
+
 /**
- * Implementation of hook_user_import_after_save().
+ * Implements hook_user_import_after_save().
  */
 function user_import_user_import_after_save($settings, $account, $password, $fields, $updated, $update_setting_per_module) {
   if (!empty($settings['send_email']) && !$updated) {
 
-		$subscribed = isset($settings['subscribed']) ? $settings['subscribed'] : NULL;
+    $subscribed = isset($settings['subscribed']) ? $settings['subscribed'] : NULL;
 
-		_user_import_send_email($account, 
-														$password, 
-														$fields, 
-														$settings['subject'], 
-														$settings['message'], 
-														$settings['message_format'], 
-														$settings['message_css'], 
-														$subscribed
-														);
-	} 
+    _user_import_send_email($account,
+                            $password,
+                            $fields,
+                            $settings['subject'],
+                            $settings['message'],
+                            $settings['message_format'],
+                            $settings['message_css'],
+                            $subscribed
+                            );
+  }
 }
 
-// Send email when account is created    
+// Send email when account is created.
 function _user_import_send_email($account, $password, $profile, $subject, $body, $format, $css, $subscribed) {
 
-    global $base_url;
+  global $base_url;
 
-	  // All system mails need to specify the module and template key (mirrored from
-	  // hook_mail()) that the message they want to send comes from.
-	  $module = 'user_import';
-	  $key = 'welcome';
-	
-	  // Specify 'to' and 'from' addresses.
-	  $to = $account->mail;
-	  $from = variable_get('site_mail', NULL);
-	  
-    $params = array(
-      '!username' => $account->name, 
-      '!uid' => $account->uid, 
-      '!site' => variable_get('site_name', 'drupal'), 
-      '!login_url' => user_pass_reset_url($account), 
-      '!password' => $password, 
-      '!uri' => $base_url, 
-      '!uri_brief' => drupal_substr($base_url, drupal_strlen('http://')), 
-      '!mailto' => $account->mail, 
-      '!date' => format_date(time()), 
-      '!login_uri' => url('user', array('absolute' => TRUE)), 
-      '!edit_uri' => url('user/'. $account->uid .'/edit', array('absolute' => TRUE)),
-      'subject' => $subject,
-      'body' => $body,
-      'email_format' => $format,
- 			'css' => $css,
-    );
-    
-    _user_import_publication_email($params, $account, $subscribed, $format);
+  // All system mails need to specify the module and template key (mirrored from
+  // hook_mail()) that the message they want to send comes from.
+  $module = 'user_import';
+  $key = 'welcome';
 
-    // import info to profile
-    if (module_exists('profile') && is_array($profile)) {
-      
-      $profile_name = _user_import_profile('fid', 'name');
-    
-      foreach ($profile_name as $fid => $field_name) {
-        $params['!' . $field_name] = $profile[$fid];
-      }
+  // Specify 'to' and 'from' addresses.
+  $to = $account->mail;
+  $from = variable_get('site_mail', NULL);
+
+  $params = array(
+    '!username' => $account->name,
+    '!uid' => $account->uid,
+    '!site' => variable_get('site_name', 'drupal'),
+    '!login_url' => user_pass_reset_url($account),
+    '!password' => $password,
+    '!uri' => $base_url,
+    '!uri_brief' => drupal_substr($base_url, drupal_strlen('http://')),
+    '!mailto' => $account->mail,
+    '!date' => format_date(time()),
+    '!login_uri' => url('user', array('absolute' => TRUE)),
+    '!edit_uri' => url('user/' . $account->uid . '/edit', array('absolute' => TRUE)),
+    'subject' => $subject,
+    'body' => $body,
+    'email_format' => $format,
+    'css' => $css,
+  );
+
+  _user_import_publication_email($params, $account, $subscribed, $format);
+
+  // Import info to profile.
+  if (module_exists('profile') && is_array($profile)) {
+
+    $profile_name = _user_import_profile('fid', 'name');
+
+    foreach ($profile_name as $fid => $field_name) {
+      $params['!' . $field_name] = $profile[$fid];
     }
+  }
 
-		$language = user_preferred_language($account);
-		
-	  // Whether or not to automatically send the mail when drupal_mail() is
-	  // called. This defaults to TRUE, and is normally what you want unless you
-	  // need to do additional processing before drupal_mail_send() is called.
-	  $send = TRUE;
+  $language = user_preferred_language($account);
 
-    $sent = drupal_mail($module, $key, $to, $language, $params, $from, $send);
-    return;
+  // Whether or not to automatically send the mail when drupal_mail() is
+  // called. This defaults to TRUE, and is normally what you want unless you
+  // need to do additional processing before drupal_mail_send() is called.
+  $send = TRUE;
+
+  $sent = drupal_mail($module, $key, $to, $language, $params, $from, $send);
+  return;
 }
 
 /**
- * Implementation of hook_mail().
+ * Implements hook_mail().
  */
 function user_import_mail($key, &$message, $params) {
 
-	switch($key) {
-  	case 'welcome':
-		$message['subject'] = (empty($params['subject'])) ? _user_mail_text('register_admin_created_subject', $message['language'], $params) : strtr($params['subject'], $params);
-		$body = (empty($params['body'])) ? _user_mail_text('register_admin_created_body', $message['language'], $params) : strtr($params['body'], $params);
+  switch ($key) {
+    case 'welcome':
+      $message['subject'] = (empty($params['subject'])) ? _user_mail_text('register_admin_created_subject', $message['language'], $params) : strtr($params['subject'], $params);
+      $body = (empty($params['body'])) ? _user_mail_text('register_admin_created_body', $message['language'], $params) : strtr($params['body'], $params);
 
-		if ($params['email_format'] == 1) {
-			$message['headers']['Content-Type'] = 'text/html; charset=UTF-8'; 
-     
-	    $body_head = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-	            <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
-	            <head>
-	            <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />';
-            
-	    if (!empty($params['css'])) $body_head .= '<style type="text/css">' . check_plain($params['css']) . '</style>';
-	    $message['body'][] = $body_head . '</head><body>' . $body . '</body></html>'; 
-		}
-		else {
-      $message['body'][] = $body;
-		}
-		
-		break; 
-	}	 
+      if ($params['email_format'] == 1) {
+        $message['headers']['Content-Type'] = 'text/html; charset=UTF-8';
+
+        $body_head = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+                <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
+                <head>
+                <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />';
+
+        if (!empty($params['css'])) {
+          $body_head .= '<style type="text/css">' . check_plain($params['css']) . '</style>';
+        }
+        $message['body'][] = $body_head . '</head><body>' . $body . '</body></html>';
+      }
+      else {
+        $message['body'][] = $body;
+      }
+      break;
+  }
 }
 
-function _user_import_edit_settings_fields(&$form, $import, $collapsed) { 
+function _user_import_edit_settings_fields(&$form, $import, $collapsed) {
 
   $form['optional'] = array(
-      '#type' => 'fieldset',
-      '#title' => t('Options'),
-      '#weight' => -85,
-      '#collapsible' => TRUE,
-      '#collapsed' => $collapsed, 
+    '#type' => 'fieldset',
+    '#title' => t('Options'),
+    '#weight' => -85,
+    '#collapsible' => TRUE,
+    '#collapsed' => $collapsed,
   );
-  
+
   $form['optional']['first_line_skip'] = array(
-      '#type' => 'checkbox',
-      '#title' => t('Ignore First Line'),
-      '#default_value' => isset($import['first_line_skip']) ? $import['first_line_skip'] : 0,
-      '#description' => t('If the first line is the names of the data columns, set to ignore first line.'),
+    '#type' => 'checkbox',
+    '#title' => t('Ignore First Line'),
+    '#default_value' => isset($import['first_line_skip']) ? $import['first_line_skip'] : 0,
+    '#description' => t('If the first line is the names of the data columns, set to ignore first line.'),
   );
-  /**
-   * @todo move contact options to a separate contact.inc support file
-   */
+
+  // @todo move contact options to a separate contact.inc support file.
   $form['optional']['contact'] = array(
-      '#type' => 'checkbox',
-      '#title' => t('Contact'),
-      '#default_value' => isset($import['contact']) ? $import['contact'] : 0,
-      '#description' => t("Set each user's personal contact form to 'allowed'."),
+    '#type' => 'checkbox',
+    '#title' => t('Contact'),
+    '#default_value' => isset($import['contact']) ? $import['contact'] : 0,
+    '#description' => t("Set each user's personal contact form to 'allowed'."),
   );
-  
+
   $form['optional']['send_email'] = array(
-      '#type' => 'checkbox',
-      '#title' => t('Send Email'),
-      '#default_value' => isset($import['send_email']) ? $import['send_email'] : 0,
-      '#description' => t('Send email to users when their account is created.'),
+    '#type' => 'checkbox',
+    '#title' => t('Send Email'),
+    '#default_value' => isset($import['send_email']) ? $import['send_email'] : 0,
+    '#description' => t('Send email to users when their account is created.'),
   );
-  
+
   $form['optional']['username_space'] = array(
-      '#type' => 'checkbox',
-      '#title' => t('Username Space'),
-      '#default_value' => isset($import['username_space']) ? $import['username_space'] : 0,
-      '#description' => t("Include spaces in usernames, e.g. 'John' + 'Smith' => 'John Smith'."),
+    '#type' => 'checkbox',
+    '#title' => t('Username Space'),
+    '#default_value' => isset($import['username_space']) ? $import['username_space'] : 0,
+    '#description' => t("Include spaces in usernames, e.g. 'John' + 'Smith' => 'John Smith'."),
   );
-  
+
   $form['optional']['activate'] = array(
-      '#type' => 'checkbox',
-      '#title' => t('Activate Accounts'),
-      '#default_value' => isset($import['activate']) ? $import['activate'] : 0,
-      '#description' => t("User accounts will not be visible to other users until their owner logs in. Select this option to make all imported user accounts visible. <strong>Note - one time login links in welcome emails will no longer work if this option is enabled.</strong>"),
+    '#type' => 'checkbox',
+    '#title' => t('Activate Accounts'),
+    '#default_value' => isset($import['activate']) ? $import['activate'] : 0,
+    '#description' => t("User accounts will not be visible to other users until their owner logs in. Select this option to make all imported user accounts visible. <strong>Note - one time login links in welcome emails will no longer work if this option is enabled.</strong>"),
+  );
+
+  $form['optional']['delimiter'] = array(
+    '#type' => 'textfield',
+    '#title' => t('File Delimiter'),
+    '#size' => 4,
+    '#default_value' => isset($import['delimiter']) ? $import['delimiter'] : ',',
+    '#description' => t("The column delimiter for the file. Use '/t' for Tab."),
   );
 
-	$form['optional']['delimiter'] = array(
-	    '#type' => 'textfield',
-	    '#title' => t('File Delimiter'),
-	    '#size' => 4,
-	    '#default_value' => isset($import['delimiter']) ? $import['delimiter'] : ',',
-	    '#description' => t("The column delimiter for the file. Use '/t' for Tab."),
-	);
-  
   return;
 }
 
 function _user_import_edit_template_fields(&$form, $import) {
-    
-  // settings template update controls
+
+  // Settings template update controls.
   if (empty($import['name'])) {
-  
-     // new settings template save controls
-      
-      $form['save'] = array(
-          '#type' => 'fieldset',
-          '#title' => t('Save Settings'),
-          '#description' => t('Save settings for re-use on other imports.'),
-          '#weight' => 90,
-          '#collapsible' => TRUE,
-          '#collapsed' => FALSE, 
-      );
-      
-       $form['save']['name'] = array(
-          '#type' => 'textfield',
-          '#title' => t('Settings Name'),
-          '#size' => 26,
-          '#maxlength' => 25,
-          '#description' => t('Name to identify these settings by.'),
-      );
-      
-      $form['save'][] = array(
-          '#type' => 'submit', 
-          '#value' => t('Save'),
-          '#validate' => array('user_import_template_has_name_validate', 'user_import_template_unique_name_validate', 'user_import_edit_form_validate'),
-          '#submit' => array('user_import_template_new_submit'),
-      );
 
-  } 
+    // New settings template save controls.
+    $form['save'] = array(
+      '#type' => 'fieldset',
+      '#title' => t('Save Settings'),
+      '#description' => t('Save settings for re-use on other imports.'),
+      '#weight' => 90,
+      '#collapsible' => TRUE,
+      '#collapsed' => FALSE,
+    );
+
+    $form['save']['name'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Settings Name'),
+      '#size' => 26,
+      '#maxlength' => 25,
+      '#description' => t('Name to identify these settings by.'),
+    );
+
+    $form['save'][] = array(
+      '#type' => 'submit',
+      '#value' => t('Save'),
+      '#validate' => array(
+        'user_import_template_has_name_validate',
+        'user_import_template_unique_name_validate',
+        'user_import_edit_form_validate',
+      ),
+      '#submit' => array('user_import_template_new_submit'),
+    );
+
+  }
   else {
-      
-      $form['save'] = array(
-          '#type' => 'fieldset',
-          '#title' => t('Saved Settings'),
-          '#description' => t("If changes have neen made to the settings since they where last saved you can update the saved template, or save them as a new template."),
-          '#weight' => 90,
-          '#collapsible' => TRUE,
-          '#collapsed' => TRUE, 
-      );
-      
-      $form['#current_template'] = $import['name'];
 
-      $form['save']['update'] = array(
-          '#type' => 'fieldset',
-          '#title' => t('Update'),
-          '#description' => t("Update '%name' settings template", array('%name' => $import['name'])),
-      );
-      
-      $form['save']['update']['submit'] = array(
-          '#type' => 'submit', 
-          '#value' => t('Update'),
-          '#validate' => array('user_import_edit_form_validate'),
-          '#submit' => array('user_import_template_update_submit'),
-      );
-          
-      $form['save']['new'] = array(
-          '#type' => 'fieldset',
-          '#title' => t('Create New'),
-          '#description' => t("Save as new settings template"),
-      );
-      
-       $form['save']['new']['name'] = array(
-          '#type' => 'textfield',
-          '#title' => t('Save As New'),
-          '#size' => 30,
-          '#maxlength' => 25,
-          '#description' => t('Name to identify these settings by.'),
-      );
-      
-      $form['save']['new'][] = array(
-          '#type' => 'submit', 
-          '#value' => t('Save As New'),
-          '#validate' => array('user_import_template_has_name_validate', 'user_import_template_unique_name_validate', 'user_import_edit_form_validate'),
-          '#submit' => array('user_import_template_new_submit'),
-      );
+    $form['save'] = array(
+      '#type' => 'fieldset',
+      '#title' => t('Saved Settings'),
+      '#description' => t("If changes have neen made to the settings since they where last saved you can update the saved template, or save them as a new template."),
+      '#weight' => 90,
+      '#collapsible' => TRUE,
+      '#collapsed' => TRUE,
+    );
+
+    $form['#current_template'] = $import['name'];
+
+    $form['save']['update'] = array(
+      '#type' => 'fieldset',
+      '#title' => t('Update'),
+      '#description' => t("Update '%name' settings template", array('%name' => $import['name'])),
+    );
+
+    $form['save']['update']['submit'] = array(
+      '#type' => 'submit',
+      '#value' => t('Update'),
+      '#validate' => array('user_import_edit_form_validate'),
+      '#submit' => array('user_import_template_update_submit'),
+    );
+
+    $form['save']['new'] = array(
+      '#type' => 'fieldset',
+      '#title' => t('Create New'),
+      '#description' => t("Save as new settings template"),
+    );
+
+    $form['save']['new']['name'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Save As New'),
+      '#size' => 30,
+      '#maxlength' => 25,
+      '#description' => t('Name to identify these settings by.'),
+    );
+
+    $form['save']['new'][] = array(
+      '#type' => 'submit',
+      '#value' => t('Save As New'),
+      '#validate' => array(
+        'user_import_template_has_name_validate',
+        'user_import_template_unique_name_validate',
+        'user_import_edit_form_validate',
+      ),
+      '#submit' => array('user_import_template_new_submit'),
+    );
   }
-  
+
   return;
 }
 
@@ -264,7 +276,9 @@ function _user_import_edit_template_fields(&$form, $import) {
  */
 function user_import_template_has_name_validate($form, &$form_state) {
   $template_name = trim($form_state['values']['name']);
-  if (empty($template_name)) form_set_error('name', t('A name needs to be set to save this settings template.')); 
+  if (empty($template_name)) {
+    form_set_error('name', t('A name needs to be set to save this settings template.'));
+  }
 }
 
 /**
@@ -273,44 +287,49 @@ function user_import_template_has_name_validate($form, &$form_state) {
 function user_import_template_unique_name_validate($form, &$form_state) {
   $template_name = trim($form_state['values']['name']);
   $unique_name = db_result(db_query("SELECT COUNT(import_id) FROM {user_import} WHERE name = '%s'", $template_name));
-  if (!empty($unique_name)) form_set_error('name', t("'!name' is already in use by another settings template.", array('!name' => $template_name))); 
+  if (!empty($unique_name)) {
+    form_set_error('name', t("'!name' is already in use by another settings template.", array(
+      '!name' => $template_name,
+      ),
+    ));
+  }
 }
 
 function _user_import_edit_remove_fields(&$form, $import) {
-        
+
   $form['remove'] = array(
-      '#type' => 'fieldset',
-      '#title' => t('Use Different CSV File'),
-      '#description' => t('Remove file to use a different file. All settings on this page will be deleted.'),
-      '#weight' => -100,
-      '#collapsible' => TRUE,
-      '#collapsed' => TRUE, 
+    '#type' => 'fieldset',
+    '#title' => t('Use Different CSV File'),
+    '#description' => t('Remove file to use a different file. All settings on this page will be deleted.'),
+    '#weight' => -100,
+    '#collapsible' => TRUE,
+    '#collapsed' => TRUE,
   );
-  
+
   $form['remove']['file'] = array(
-      '#type' => 'item', 
-      '#title' => t('Uploaded file'),
-      '#value' => $import['filename']
+    '#type' => 'item',
+    '#title' => t('Uploaded file'),
+    '#value' => $import['filename'],
   );
 
   $form['remove']['submit'] = array(
-      '#type' => 'submit', 
-      '#value' => t('Remove file'),
-      '#validate' => array('user_import_edit_remove_file_validate'),
+    '#type' => 'submit',
+    '#value' => t('Remove file'),
+    '#validate' => array('user_import_edit_remove_file_validate'),
   );
 
   return;
 }
 
 /**
- *  Delete settings and uploaded file
+ * Delete settings and uploaded file.
  */
-function user_import_edit_remove_file_validate($form, &$form_state) { 
+function user_import_edit_remove_file_validate($form, &$form_state) {
 
   $settings = _user_import_settings_select($form_state['values']['import_id']);
   _user_import_settings_deletion($form_state['values']['import_id']);
   _user_import_file_deletion($settings['filepath'], $settings['filename'], $settings['oldfilename'], $settings['options']['ftp']);
-  drupal_goto('admin/user/user_import/add');  
+  drupal_goto('admin/user/user_import/add');
 }
 
 function _user_import_publication_email(&$variables, $account, $subscribed, $format) {
@@ -321,31 +340,31 @@ function _user_import_publication_email(&$variables, $account, $subscribed, $for
 
   $id_hash = identity_hash_select_hash($account->uid);
   $variables['!id_hash'] = $id_hash->hash;
-  
+
   while (list($type, $subscriptions) = each($subscribed)) {
 
     while (list($publication_id, $shedule) = each($subscriptions)) {
 
       if (!empty($shedule[0])) {
- 
+
         $publication = publication_select_publications($type, $publication_id);
-        
+
         $update_link = url('subscribed/preferences/' . $publication_id . '/' . $id_hash->hash, array('absolute' => TRUE));
         $unsubscribe_link = url('subscribed/delete/' . $publication_id . '/' . $id_hash->hash, array('absolute' => TRUE));
-        
+
         if ($format == 1) {
-         
+
           $variables['!subscribed_links'] .= '<strong>' . $publication->title . '</strong><br />' .
           '<a href="' . $update_link . '">' . t('Update Preferences') . '</a> | <a href="' . $unsubscribe_link . '">' . t('Unsubscribe') . '</a><br />';
 
         }
         else {
-        
+
           $variables['!subscribed_links'] .= $publication->title . "\n" .
-          ' - ' . t('Update Preferences') . ' ' . $update_link . '\n' .
-          ' - ' . t('Unsubscribe') . ' ' . $unsubscribe_link . '\n';
+          ' - ' . t('Update Preferences') . ' ' . $update_link . "\n" .
+          ' - ' . t('Unsubscribe') . ' ' . $unsubscribe_link . "\n";
         }
       }
     }
-  }  
+  }
 }
diff --git a/supported/watchdog.inc b/supported/watchdog.inc
index 5512ace..12e11b9 100644
--- a/supported/watchdog.inc
+++ b/supported/watchdog.inc
@@ -1,17 +1,21 @@
 <?php
-
 /**
- * @todo add option to not record watchdog messages for each user created
- * on large imports user import could add a lot of rows to the watchdog table
+ * @file
+ * Watchdog.inc
  */
 
+// @todo add option to not record watchdog messages for each user created
+// on large imports user import could add a lot of rows to the watchdog table
 /**
- * Implementation of hook_user_import_after_save().
+ * Implements hook_user_import_after_save().
  */
 function watchdog_user_import_after_save($settings, $account, $password, $fields, $updated) {
 
   if (empty($updated)) {
-    watchdog('user', 'New user: %name %email.', array('%name' => $account->name, '%email' => '<'. $account->mail .'>'), WATCHDOG_NOTICE, l(t('edit'), 'user/'. $account->uid .'/edit'));
+    watchdog('user', 'New user: %name %email.', array(
+      '%name' => $account->name,
+      '%email' => '<' . $account->mail . '>',
+    ), WATCHDOG_NOTICE, l(t('edit'), 'user/' . $account->uid . '/edit'));
   }
   return;
-}
\ No newline at end of file
+}
diff --git a/user_import.admin.inc b/user_import.admin.inc
index 3e46a9b..0ae27fd 100644
--- a/user_import.admin.inc
+++ b/user_import.admin.inc
@@ -1,5 +1,4 @@
 <?php
-
 /**
  * @file
  * Provide administration configuration pages to import users.
@@ -7,42 +6,43 @@
 
 function user_import_list($action = NULL, $import_id = NULL) {
 
-	// clear incomplete imports
-	_user_import_incomplete_deletion();
-
-	if (!empty($import_id) && is_numeric($import_id)) {
-
-	  $pager_id = 1;
-	  $max = 25;
-	  $import = _user_import_settings_select($import_id);
-  
-	  $total = db_result(db_query("SELECT count(data) FROM {user_import_errors} WHERE import_id = %d", $import['import_id']));
-	  $results = pager_query("SELECT * FROM {user_import_errors} WHERE import_id = %d", $max, $pager_id, NULL, array($import['import_id']));
-  
-	  while ($line = db_fetch_array($results)) {
-
-	   $line['data'] = unserialize($line['data']);
-	      $line['errors'] = unserialize($line['errors']); 
-      
-	      $file_lines[] = $line;
-	  }
-  
-	  $output = theme('user_import_errors_display', $import, $file_lines, $total);
-	  $output .= theme('pager', NULL, $max, $pager_id);
-
-	} else {
-  
-	  $output =  theme('user_import_list');
-	}
-
-	return $output;    
+  // Clear incomplete imports.
+  _user_import_incomplete_deletion();
+
+  if (!empty($import_id) && is_numeric($import_id)) {
+
+    $pager_id = 1;
+    $max = 25;
+    $import = _user_import_settings_select($import_id);
+
+    $total = db_result(db_query("SELECT count(data) FROM {user_import_errors} WHERE import_id = %d", $import['import_id']));
+    $results = pager_query("SELECT * FROM {user_import_errors} WHERE import_id = %d", $max, $pager_id, NULL, array($import['import_id']));
+
+    while ($line = db_fetch_array($results)) {
+
+      $line['data'] = unserialize($line['data']);
+      $line['errors'] = unserialize($line['errors']);
+
+      $file_lines[] = $line;
+    }
+
+    $output = theme('user_import_errors_display', $import, $file_lines, $total);
+    $output .= theme('pager', NULL, $max, $pager_id);
+
+  }
+  else {
+    $output = theme('user_import_list');
+  }
+
+  return $output;
 }
 
 function user_import_preferences($import_id = NULL, $template_id = NULL) {
 
   if (empty($import_id)) {
     $output = drupal_get_form('user_import_add_form');
-  } else { 
+  }
+  else {
     $output = drupal_get_form('user_import_edit', $import_id, $template_id);
   }
 
@@ -51,153 +51,160 @@ function user_import_preferences($import_id = NULL, $template_id = NULL) {
 
 function user_import_continue($import_id = NULL) {
 
-	if (!empty($import_id) && is_numeric($import_id)) {
+  if (!empty($import_id) && is_numeric($import_id)) {
     module_load_include('inc', 'user_import', 'user_import.import');
-		$import = _user_import_settings_select($import_id);
-		_user_import_process($import);
-	}
+    $import = _user_import_settings_select($import_id);
+    _user_import_process($import);
+  }
 
-	drupal_goto('admin/user/user_import');
+  drupal_goto('admin/user/user_import');
 }
 
 function user_import_import($import_id = NULL) {
 
-	if (!empty($import_id) && is_numeric($import_id)) {
-    
-		$import = _user_import_settings_select($import_id);
-		_user_import_initialise_import($import); 
-	}
+  if (!empty($import_id) && is_numeric($import_id)) {
 
-	drupal_goto('admin/user/user_import');
+    $import = _user_import_settings_select($import_id);
+    _user_import_initialise_import($import);
+  }
+
+  drupal_goto('admin/user/user_import');
 }
 
 function user_import_delete($import_id = NULL, $return_path = 'admin/user/user_import') {
 
-	if (empty($import_id) || !is_numeric($import_id)) drupal_goto($return_path);
-    
-	$import = _user_import_settings_select($import_id);   
-	_user_import_settings_deletion($import_id);
-	_user_import_file_deletion($import['filepath'], $import['filename'], $import['oldfilename'], $import['ftp']);
-	drupal_goto($return_path);
-	return; 
+  if (empty($import_id) || !is_numeric($import_id)) {
+    drupal_goto($return_path);
+  }
+
+  $import = _user_import_settings_select($import_id);
+  _user_import_settings_deletion($import_id);
+  _user_import_file_deletion($import['filepath'], $import['filename'], $import['oldfilename'], $import['ftp']);
+  drupal_goto($return_path);
+  return;
 }
 
 /**
- * Configuration form define (settings affect all user imports)
+ * Configuration form define (settings affect all user imports).
  */
-function user_import_configure_form() { 
-        
-    $form['performance'] = array(
-        '#type' => 'fieldset',
-        '#title' => t('Performance'),
-        '#collapsible' => TRUE,
-        '#collapsed' => TRUE,
-    );
+function user_import_configure_form() {
+
+  $form['performance'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Performance'),
+    '#collapsible' => TRUE,
+    '#collapsed' => TRUE,
+  );
+
+  $form['performance']['user_import_max'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Maximum Users/Process'),
+    '#default_value' => variable_get('user_import_max', 250),
+    '#size' => 10,
+    '#maxlength' => 10,
+    '#description' => t('Maximum number of users to import each time the file is processed, useful for controlling the rate at which emails are sent out.'),
+  );
+
+  $form['performance']['user_import_line_max'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Maximum length of line'),
+    '#default_value' => variable_get('user_import_line_max', 1000),
+    '#size' => 10,
+    '#maxlength' => 10,
+    '#description' => t('The default is set at 1,000 characters, if a line in your csv is longer than this you should set a higher maximum here. Setting higher maximums will slow down imports.'),
+  );
 
-    $form['performance']['user_import_max'] = array(
-        '#type' => 'textfield',
-        '#title' => t('Maximum Users/Process'),
-        '#default_value' => variable_get('user_import_max', 250),
-        '#size' => 10,
-        '#maxlength' => 10,
-        '#description' => t('Maximum number of users to import each time the file is processed, useful for controling the rate at which emails are sent out.'),
+  if (module_exists('profile')) {
+    $date_options = array(
+      'MM/DD/YYYY' => 'MM/DD/YYYY',
+      'DD/MM/YYYY' => 'DD/MM/YYYY',
+      'YYYY/MM/DD' => 'YYYY/MM/DD',
+      'YYYY/DD/MM' => 'YYYY/DD/MM',
     );
-    
-    $form['performance']['user_import_line_max'] = array(
-        '#type' => 'textfield',
-        '#title' => t('Maximum length of line'),
-        '#default_value' =>  variable_get('user_import_line_max', 1000),
-        '#size' => 10,
-        '#maxlength' => 10,
-        '#description' => t('The default is set at 1,000 characters, if a line in your csv is longer than this you should set a higher maximum here. Setting higher maximums will slow down imports.'),
+    $form['profile'] = array(
+      '#type' => 'fieldset',
+      '#title' => t('Profile Settings'),
+      '#collapsible' => TRUE,
+      '#collapsed' => TRUE,
     );
+    $form['profile']['profile_date_format'] = array(
+      '#type' => 'select',
+      '#title' => t('Date field format'),
+      '#description' => t('Select a format for importing dates into user profiles (Profile module).'),
+      '#default_value' => variable_get('user_import_profile_date_format', 'MM/DD/YYYY'),
+      '#options' => $date_options,
+    );
+  }
+
+  $saved_templates = _user_import_settings_select(NULL, TRUE);
 
-	  if (module_exists('profile')) {
-	    $date_options = array(
-	      'MM/DD/YYYY' => 'MM/DD/YYYY',
-	      'DD/MM/YYYY' => 'DD/MM/YYYY',
-	      'YYYY/MM/DD' => 'YYYY/MM/DD',
-	      'YYYY/DD/MM' => 'YYYY/DD/MM',
-	    );
-	    $form['profile'] = array(
-	      '#type' => 'fieldset',
-	      '#title' => t('Profile Settings'),
-	      '#collapsible' => TRUE,
-	      '#collapsed' => TRUE,
-	    );
-	    $form['profile']['profile_date_format'] = array(
-	      '#type' => 'select',
-	      '#title' => t('Date field format'),
-	      '#description' => t('Select a format for importing dates into user profiles (Profile module).'),
-	      '#default_value' => variable_get('user_import_profile_date_format', 'MM/DD/YYYY'),
-	      '#options' => $date_options,
-	    );
-	  }
+  if (!empty($saved_templates)) {
+
+    $form['settings_templates'] = array(
+      '#type' => 'fieldset',
+      '#title' => t('Settings Templates'),
+      '#collapsible' => TRUE,
+      '#collapsed' => TRUE,
+    );
 
-    $saved_templates = _user_import_settings_select(NULL, TRUE);
-    
-    if (!empty($saved_templates)) {
- 
-        $form['settings_templates'] = array(
-            '#type' => 'fieldset',
-            '#title' => t('Settings Templates'),
-            '#collapsible' => TRUE,
-            '#collapsed' => TRUE,
-        );
-        
-        $templates_list = array('-- none --');
-        
-        foreach ($saved_templates AS $template) {
-            $templates_list[$template['import_id']] = $template['name'];
-            $templates_delete[$template['import_id']] = $template['name'];
-        }
-        
-        $form['settings_templates']['user_import_settings'] = array( 
-            '#type' => 'select',
-            '#title' => t('Default Settings'),
-            '#description' => t('Select if you want to use a previously saved set of settings as default for all imports.'),
-            '#default_value' => variable_get('user_import_settings', 0),
-            '#options' => $templates_list,
-        );
+    $templates_list = array('-- none --');
 
-        
-        $form['settings_templates']['templates'] = array(
-            '#type' => 'checkboxes',
-            '#title' => t('Delete Templates'),
-            '#options' => $templates_delete,
-        );
-    
+    foreach ($saved_templates as $template) {
+      $templates_list[$template['import_id']] = $template['name'];
+      $templates_delete[$template['import_id']] = $template['name'];
     }
-    
-    $form['submit'] = array(
-        '#type' => 'submit', 
-        '#value' => t('Save'),
-        );
-    
-    return $form;
+
+    $form['settings_templates']['user_import_settings'] = array(
+      '#type' => 'select',
+      '#title' => t('Default Settings'),
+      '#description' => t('Select if you want to use a previously saved set of settings as default for all imports.'),
+      '#default_value' => variable_get('user_import_settings', 0),
+      '#options' => $templates_list,
+    );
+
+    $form['settings_templates']['templates'] = array(
+      '#type' => 'checkboxes',
+      '#title' => t('Delete Templates'),
+      '#options' => $templates_delete,
+    );
+
+  }
+
+  $form['submit'] = array(
+    '#type' => 'submit',
+    '#value' => t('Save'),
+  );
+
+  return $form;
 }
 
 function user_import_configure_form_validate($form, &$form_state) {
 
-    if (is_numeric($form_state['values']['user_import_max'])) {
-        if ($form_state['values']['user_import_max'] < 10) form_set_error('user_import_max', t("Value should be at least 10."));       
-    } 
-    else {
-        form_set_error('user_import_max', t('Value must be a number.'));
+  if (is_numeric($form_state['values']['user_import_max'])) {
+    if ($form_state['values']['user_import_max'] < 10) {
+      form_set_error('user_import_max', t("Value should be at least 10."));
     }
-    
-    if (is_numeric($form_state['values']['user_import_line_max'])) {
-        if ($form_state['values']['user_import_line_max'] < 1000) form_set_error('user_import_line_max', t("Value must be higher than 1000."));
-        if ($form_state['values']['user_import_line_max'] > 1000000) form_set_error('user_import_line_max', t("Value must be lower than 1,000,000."));
-    } 
-    else {
-        form_set_error('user_import_line_max', t('Value must be a number.'));
+  }
+  else {
+    form_set_error('user_import_max', t('Value must be a number.'));
+  }
+
+  if (is_numeric($form_state['values']['user_import_line_max'])) {
+    if ($form_state['values']['user_import_line_max'] < 1000) {
+      form_set_error('user_import_line_max', t("Value must be higher than 1000."));
     }
-    
-    return;
+    if ($form_state['values']['user_import_line_max'] > 1000000) {
+      form_set_error('user_import_line_max', t("Value must be lower than 1,000,000."));
+    }
+  }
+  else {
+    form_set_error('user_import_line_max', t('Value must be a number.'));
+  }
+
+  return;
 }
 
-function user_import_configure_form_submit($form, &$form_state) { 
+function user_import_configure_form_submit($form, &$form_state) {
 
   settype($form_state['values']['user_import_max'], 'integer');
   settype($form_state['values']['user_import_line_max'], 'integer');
@@ -205,76 +212,77 @@ function user_import_configure_form_submit($form, &$form_state) {
   variable_set('user_import_line_max', $form_state['values']['user_import_line_max']);
   variable_set('user_import_settings', $form_state['values']['user_import_settings']);
   $profile_date_format = isset($form_state['values']['profile_date_format']) ? $form_state['values']['profile_date_format'] : 0;
-	variable_set('user_import_profile_date_format', $profile_date_format);
+  variable_set('user_import_profile_date_format', $profile_date_format);
 
   if (!empty($form_state['values']['templates'])) {
 
-      foreach ($form_state['values']['templates'] as $import_id) {
-        
-          if (!empty($import_id)) {
-        
-              $template = _user_import_settings_select($import_id);
-              if (!empty($deleted)) $deleted .= ', ';
-              $deleted .= $template['name'];       
-              _user_import_settings_deletion($import_id);
-          }
+    foreach ($form_state['values']['templates'] as $import_id) {
+
+      if (!empty($import_id)) {
+
+        $template = _user_import_settings_select($import_id);
+        if (!empty($deleted)) {
+          $deleted .= ', ';
+        }
+        $deleted .= $template['name'];
+        _user_import_settings_deletion($import_id);
       }
+    }
   }
 
-  if (!empty($deleted)) drupal_set_message(t('Settings templates deleted: @deleted', array('@deleted' => $deleted)));
+  if (!empty($deleted)) {
+    drupal_set_message(t('Settings templates deleted: @deleted', array('@deleted' => $deleted)));
+  }
 
   drupal_set_message(t('Configuration settings have been saved.'));
   $form_state['redirect'] = 'admin/user/user_import';
 }
 
 function user_import_add_form($import_id = NULL) {
-        
-    $form = array();
-    $ftp_files = _user_import_ftp_files();
-    user_import_add_file_form($form, $ftp_files);
-    user_import_delimiter_form($form);    
-    $settings = _user_import_settings_select(NULL, TRUE);
-    
-    if ($settings) {
- 
-        $saved_settings = array(t('-- none --'));
-        foreach ($settings AS $settings_set) {
-            $saved_settings[$settings_set['import_id']] = $settings_set['name'];
-        }
-           
-        $form['import_template_select'] = array( 
-            '#type' => 'select',
-            '#title' => t('Saved Settings'),
-            '#description' => t('Select if you want to use a previously saved set of settings.'),
-            '#default_value' => variable_get('user_import_settings', 0),
-            '#options' => $saved_settings,
-        );
-        
-    } 
- 
-    $form['next'] = array(
-        '#type' => 'submit', 
-        '#value' => t('Next')
-    );    
-    
-    // Set form parameters so we can accept file uploads.
-    $form['#attributes'] = array('enctype' => 'multipart/form-data'); 
 
-    return $form;    
+  $form = array();
+  $ftp_files = _user_import_ftp_files();
+  user_import_add_file_form($form, $ftp_files);
+  user_import_delimiter_form($form);
+  $settings = _user_import_settings_select(NULL, TRUE);
+
+  if ($settings) {
+    $saved_settings = array(t('-- none --'));
+    foreach ($settings as $settings_set) {
+      $saved_settings[$settings_set['import_id']] = $settings_set['name'];
+    }
+
+    $form['import_template_select'] = array(
+      '#type' => 'select',
+      '#title' => t('Saved Settings'),
+      '#description' => t('Select if you want to use a previously saved set of settings.'),
+      '#default_value' => variable_get('user_import_settings', 0),
+      '#options' => $saved_settings,
+    );
+  }
+
+  $form['next'] = array(
+    '#type' => 'submit',
+    '#value' => t('Next'),
+  );
+
+  // Set form parameters so we can accept file uploads.
+  $form['#attributes'] = array('enctype' => 'multipart/form-data');
+
+  return $form;
 }
 
 function user_import_add_form_validate($form, &$form_state) {
 
   $file = _user_import_file(NULL, $form_state['values']['file_ftp']);
 
-  // check file uploaded OK
-  if (empty($file->filename)) form_set_error('file_upload', t('A file must be uploaded or selected from FTP updates.'));
+  // Check file uploaded OK.
+  if (empty($file->filename)) {
+    form_set_error('file_upload', t('A file must be uploaded or selected from FTP updates.'));
+  }
 
-  /**
-   * @todo check file matches saved settings selected 
-   */
-
-  return; 
+  // @todo check file matches saved settings selected
+  return;
 }
 
 function user_import_add_form_submit($form, &$form_state) {
@@ -286,35 +294,37 @@ function user_import_add_form_submit($form, &$form_state) {
   $form_state['values']['filepath'] = $file->filepath;
   $form_state['values']['setting'] = 'file set';
 
-  // create import setting
+  // Create import setting.
   $import = _user_import_settings_save($form_state['values']);
-  if (!empty($form_state['values']['import_template_select'])) $settings_template = check_plain($form_state['values']['import_template_select']);
+  if (!empty($form_state['values']['import_template_select'])) {
+    $settings_template = check_plain($form_state['values']['import_template_select']);
+  }
 
-  $form_state['redirect'] = 'admin/user/user_import/add/'. $import['import_id'] .'/'. $settings_template; 
+  $form_state['redirect'] = 'admin/user/user_import/add/' . $import['import_id'] . '/' . $settings_template;
 }
 
 function user_import_delimiter_form(&$form, $value = ',') {
   $form['file_settings'] = array(
-      '#type' => 'fieldset',
-      '#title' => t('File Settings'),
-      '#collapsible' => TRUE,
-			'#collapsed' => TRUE,
-      '#description' => t("File column delimiter"),
+    '#type' => 'fieldset',
+    '#title' => t('File Settings'),
+    '#collapsible' => TRUE,
+    '#collapsed' => TRUE,
+    '#description' => t("File column delimiter"),
   );
 
   $form['file_settings']['delimiter'] = array(
-      '#type' => 'textfield',
-      '#title' => t('Delimiter'),
-      '#size' => 4,
-      '#default_value' => $value,
-      '#required' => TRUE,
-      '#description' => t("The column delimiter for the file. Use '/t' for Tab."),
+    '#type' => 'textfield',
+    '#title' => t('Delimiter'),
+    '#size' => 4,
+    '#default_value' => $value,
+    '#required' => TRUE,
+    '#description' => t("The column delimiter for the file. Use '/t' for Tab."),
   );
 }
 
 function user_import_edit($form_state, $import_id, $template_id = NULL) {
 
-  // load code for supported modules  
+  // Load code for supported modules.
   user_import_load_supported();
 
   $form = array();
@@ -322,45 +332,49 @@ function user_import_edit($form_state, $import_id, $template_id = NULL) {
   $import['template_id'] = $template_id;
 
   $form['ftp'] = array(
-      '#type' => 'value', 
-      '#value' => $import['options']['ftp'],
+    '#type' => 'value',
+    '#value' => $import['options']['ftp'],
   );
-  
-  // add setting template values
-  if ($import['setting'] == 'file set') $import = _user_import_initialise_import($import);
-  
+
+  // Add setting template values.
+  if ($import['setting'] == 'file set') {
+    $import = _user_import_initialise_import($import);
+  }
+
   $form['import_id'] = array(
-      '#type' => 'value', 
-      '#value' => $import_id,
+    '#type' => 'value',
+    '#value' => $import_id,
   );
 
   $form['setting'] = array(
-      '#type' => 'value', 
-      '#value' => $import['setting'],
+    '#type' => 'value',
+    '#value' => $import['setting'],
   );
-  
+
   $form['return_path'] = array(
-      '#type' => 'value', 
-      '#default_value' => 'admin/user/user_import',
+    '#type' => 'value',
+    '#default_value' => 'admin/user/user_import',
   );
-  
+
   $form['og_id'] = array(
-      '#type' => 'value', 
-      '#default_value' => 0,
+    '#type' => 'value',
+    '#default_value' => 0,
   );
 
   // don't use hook because these need to be added in this order;
   user_import_edit_file_fields($form, $import);
   user_import_form_field_match($form, $import);
-  
+
   $collapsed = (empty($import['name'])) ? FALSE: TRUE;
   $additional_fieldsets = module_invoke_all('user_import_form_fieldset', $import, $collapsed);
-  if (is_array($additional_fieldsets)) $form = $form + $additional_fieldsets;
+  if (is_array($additional_fieldsets)) {
+    $form = $form + $additional_fieldsets;
+  }
 
   $update_user = module_invoke_all('user_import_form_update_user');
 
   if (is_array($update_user)) {
-    
+
     $form['update_user'] = array(
       '#type' => 'fieldset',
       '#title' => t('Update Existing Users'),
@@ -370,59 +384,67 @@ function user_import_edit($form_state, $import_id, $template_id = NULL) {
     );
 
     foreach ($update_user as $module => $display) {
-      
-      $options = array(UPDATE_NONE => t('No Update'), UPDATE_REPLACE => t('Replace Data'), UPDATE_ADD => t('Add Data'));
-      if (isset($display['exclude_add']) && $display['exclude_add'] == TRUE) unset($options[UPDATE_ADD]);
-      if (isset($display['exclude_replace']) && $display['exclude_replace'] == TRUE) unset($options[UPDATE_REPLACE]);
-         
+
+      $options = array(
+        UPDATE_NONE => t('No Update'),
+        UPDATE_REPLACE => t('Replace Data'),
+        UPDATE_ADD => t('Add Data'),
+      );
+      if (isset($display['exclude_add']) && $display['exclude_add'] == TRUE) {
+        unset($options[UPDATE_ADD]);
+      }
+      if (isset($display['exclude_replace']) && $display['exclude_replace'] == TRUE) {
+        unset($options[UPDATE_REPLACE]);
+      }
+
       $form['update_user'][$module] = array(
         '#type' => 'radios',
         '#title' => $display['title'],
         '#options' => $options,
         '#default_value' => empty($import['options']['update_user'][$module]) ? UPDATE_NONE : $import['options']['update_user'][$module],
         '#description' => $display['description'],
-      );  
+      );
     }
   }
 
-  // don't show test option if import has started
+  // Don't show test option if import has started.
   if ($import['setting'] != 'import' && $import['setting'] != 'imported') {
 
     $form['test'] = array(
-        '#type' => 'submit', 
-        '#value' => t('Test'),
-        '#weight' => 100,
-        '#submit' => array('user_import_test_submit', 'user_import_edit_submit'),
+      '#type' => 'submit',
+      '#value' => t('Test'),
+      '#weight' => 100,
+      '#submit' => array('user_import_test_submit', 'user_import_edit_submit'),
     );
   }
 
   $form['import'] = array(
-      '#type' => 'submit', 
-      '#value' => t('Import'),
-      '#weight' => 100,
-			'#submit' => array('user_import_import_submit', 'user_import_edit_submit'),
+    '#type' => 'submit',
+    '#value' => t('Import'),
+    '#weight' => 100,
+    '#submit' => array('user_import_import_submit', 'user_import_edit_submit'),
   );
-  
+
   $form['cancel'] = array(
-      '#type' => 'submit', 
-      '#value' => t('Cancel'),
-      '#weight' => 100,
-      '#validate' => array('user_import_edit_cancel_validate'),
-  ); 
+    '#type' => 'submit',
+    '#value' => t('Cancel'),
+    '#weight' => 100,
+    '#validate' => array('user_import_edit_cancel_validate'),
+  );
 
-  return $form;  
+  return $form;
 }
 
-function user_import_edit_cancel_validate($form, &$form_state) { 
-	
-  // if import was being added - delete file
+function user_import_edit_cancel_validate($form, &$form_state) {
+
+  // If import was being added - delete file.
   if ($form_state['values']['setting'] == 'file set') {
-	  $settings = _user_import_settings_select($form_state['values']['import_id']);
-	  _user_import_settings_deletion($form_state['values']['import_id']);
-	  _user_import_file_deletion($settings['filepath'], $settings['filename'], $settings['oldfilename'], $settings['options']['ftp']); 
+    $settings = _user_import_settings_select($form_state['values']['import_id']);
+    _user_import_settings_deletion($form_state['values']['import_id']);
+    _user_import_file_deletion($settings['filepath'], $settings['filename'], $settings['oldfilename'], $settings['options']['ftp']);
   }
 
-  $form_state['redirect'] = 'admin/user/user_import'; 
+  $form_state['redirect'] = 'admin/user/user_import';
 }
 
 function user_import_edit_validate($form, &$form_state) {
@@ -431,219 +453,226 @@ function user_import_edit_validate($form, &$form_state) {
 
   foreach ($form_state['values']['field_match'] as $row => $values) {
 
-    // check each field is unique
+    // Check each field is unique.
     if ($values['field_match'] != '0' && $values['field_match'] != '-------------' && in_array($values['field_match'], $fields)) {
       form_set_error('field_match', t('Database fields can only be matched to one column of the csv file.'));
     }
- 
+
     $fields[$values['field_match']] = $values['field_match'];
- 
-    // check email address has been selected
-    if ($values['field_match'] == 'user-email') $email = TRUE;
+
+    // Check email address has been selected.
+    if ($values['field_match'] == 'user-email') {
+      $email = TRUE;
+    }
   }
 
-  if (!$email) form_set_error('email', t('One column of the csv file must be set as the email address.'));
+  if (!$email) {
+    form_set_error('email', t('One column of the csv file must be set as the email address.'));
+  }
 
   if ($form_state['values']['name']) {
-     $form_state['values']['name'] = rtrim($form_state['values']['name']);
-   
-     if (drupal_strlen($form_state['values']['name']) < 1 || drupal_strlen($form_state['values']['name']) > 25) {
+    $form_state['values']['name'] = rtrim($form_state['values']['name']);
+    if (drupal_strlen($form_state['values']['name']) < 1 || drupal_strlen($form_state['values']['name']) > 25) {
       form_set_error('name', t('Name of saved settings must be 25 characters or less.'));
-     }
-  }  
-    
+    }
+  }
+
   return;
 }
 
 /**
- *  Save a new template.
+ * Save a new template.
  */
 function user_import_template_new_submit($form, &$form_state) {
 
-  // save settings for import
+  // Save settings for import.
   _user_import_settings_save($form_state['values']);
 
-  // save settings for template
+  // Save settings for template.
   $import_id = $form_state['values']['import_id'];
   $form_state['values']['setting'] = 'template';
   unset($form_state['values']['import_id']);
   _user_import_initialise_import($form_state['values']);
   drupal_set_message(t("'%name' was saved as a settings template.", array('%name' => $form_state['values']['name'])));
 
-  // reload settings page
+  // Reload settings page.
   $form_state['redirect'] = 'admin/user/user_import/add/' . $import_id;
-  return; 
+  return;
 }
 
 /**
- *  Update an existing template.
+ * Update an existing template.
  */
 function user_import_template_update_submit($form, &$form_state) {
 
-  // save settings for import
+  // Save settings for import.
   $import_id = $form_state['values']['import_id'];
   _user_import_settings_save($form_state['values']);
 
-  // get template details
+  // Get template details.
   $template_id = db_result(db_query("SELECT import_id from {user_import} where setting = 'template' AND name= '%s' LIMIT 1", $form['#current_template']));
 
-  // save settings for template 
+  // Save settings for template.
   $form_state['values']['setting'] = 'template';
   $form_state['values']['import_id'] = $template_id;
   $form_state['values']['name'] = $form['#current_template'];
   _user_import_initialise_import($form_state['values']);
-  drupal_set_message (t("'%name' settings template was updated.", array('%name' => $form['#current_template'])));
+  drupal_set_message(t("'%name' settings template was updated.", array('%name' => $form['#current_template'])));
 
-  // reload settings page
+  // Reload settings page.
   $form_state['redirect'] = 'admin/user/user_import/add/' . $import_id;
-  return; 
+  return;
 }
 
 /**
- * 
+ * User_import_test_submit function.
  */
 function user_import_test_submit($form, &$form_state) {
-  $form_state['values']['setting'] = 'test'; 
-  drupal_set_message(t('Tested')); 
+  $form_state['values']['setting'] = 'test';
+  drupal_set_message(t('Tested'));
 }
 
 /**
- * 
+ * User_import_import_submit function.
  */
 function user_import_import_submit($form, &$form_state) {
-	$form_state['values']['setting'] = 'import'; 
-	drupal_set_message (t('Imported'));
+  $form_state['values']['setting'] = 'import';
+  drupal_set_message(t('Imported'));
 }
 
 /**
- * 
+ * User_import_edit_submit function.
  */
 function user_import_edit_submit($form, &$form_state) {
   // Deal with import being canceled.
   if ($form_state['clicked_button']['#value'] == t('Cancel')) {
     $form_state['redirect'] = 'admin/user/user_import';
-	  return;
+    return;
   }
 
   module_load_include('inc', 'user_import', 'user_import.import');
-	if ($form_state['values']['setting'] == 'file set') $filepath = file_move($form_state['values']['filepath'], file_directory_path() . '/' . $form_state['values']['filename']);
-	if (!empty($form_state['values']['og_id'])) $form_state['values']['groups'][$form_state['values']['og_id']] = $form_state['values']['og_id'];
-	$form_state['values']['ftp'] = $form_state['values']['ftp'];
+  if ($form_state['values']['setting'] == 'file set') {
+    $filepath = file_move($form_state['values']['filepath'], file_directory_path() . '/' . $form_state['values']['filename']);
+  }
+  if (!empty($form_state['values']['og_id'])) {
+    $form_state['values']['groups'][$form_state['values']['og_id']] = $form_state['values']['og_id'];
+  }
+  $form_state['values']['ftp'] = $form_state['values']['ftp'];
   $form_state['values'] = _user_import_settings_save($form_state['values']);
   $form_state['values']['save']['update'] = NULL;
   $form_state['values']['import_template_id'] = NULL;
   $form_state['values']['save']['name'] = NULL;
   $form_state['redirect'] = $form_state['values']['return_path'];
-  _user_import_process($form_state['values']); 
+  _user_import_process($form_state['values']);
 }
 
 function user_import_add_file_form(&$form, $ftp_files = NULL) {
 
-    $form['browser'] = array(
-        '#type' => 'fieldset',
-        '#title' => t('Browser Upload'),
-        '#collapsible' => TRUE,
-        '#description' => t("Upload a CSV file."),
+  $form['browser'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Browser Upload'),
+    '#collapsible' => TRUE,
+    '#description' => t("Upload a CSV file."),
+  );
+
+  if (function_exists('file_upload_max_size')) {
+    $file_size = t('Maximum file size: %size.', array('%size' => format_size(file_upload_max_size())));
+  }
+
+  $form['browser']['file_upload'] = array(
+    '#type' => 'file',
+    '#title' => t('CSV File'),
+    '#size' => 40,
+    '#description' => t('Select the CSV file to be imported. ') . $file_size,
+  );
+
+  if (!empty($ftp_files)) {
+
+    $form['ftp'] = array(
+      '#type' => 'fieldset',
+      '#title' => t('FTP Upload'),
+      '#collapsible' => TRUE,
+      '#collapsed' => TRUE,
+      '#description' => t("Any files uploaded to the 'user_import' directory using FTP can be selected for import here. Useful if the import file is too large for upload via the browser."),
     );
-    
-		if (function_exists('file_upload_max_size')) {
-      $file_size = t('Maximum file size: %size.', array('%size' => format_size(file_upload_max_size())));
-    }
 
-    $form['browser']['file_upload'] = array(
-        '#type' => 'file',
-        '#title' => t('CSV File'),
-        '#size' => 40,
-        '#description' => t('Select the CSV file to be imported. ') . $file_size,
+    $form['ftp']['file_ftp'] = array(
+      '#type' => 'radios',
+      '#title' => t('Files'),
+      '#default_value' => 0,
+      '#options' => $ftp_files,
     );
 
-    if (!empty($ftp_files)) {
+    // Reload the page to show any files that have been added by FTP.
+    $form['ftp']['scan'] = array(
+      '#type' => 'submit',
+      '#value' => t('Check for new files'),
+      '#validate' => array(),
+      '#submit' => array(),
+    );
+  }
 
-      $form['ftp'] = array(
-          '#type' => 'fieldset',
-          '#title' => t('FTP Upload'),
-          '#collapsible' => TRUE,
-          '#collapsed' => TRUE,
-          '#description' => t("Any files uploaded to the 'user_import' directory using FTP can be selected for import here. Useful if the import file is too large for upload via the browser."),
-      );
-      
-       $form['ftp']['file_ftp'] = array(
-            '#type' => 'radios',
-            '#title' => t('Files'),
-            '#default_value' => 0,
-            '#options' => $ftp_files,
-       );
-      
-      // reload the page to show any files that have been added by FTP
-      $form['ftp']['scan'] = array(
-          '#type' => 'submit', 
-          '#value' => t('Check for new files'),
-          '#validate' => array(),
-          '#submit' => array(),
-      );
-        
-    }
-    
-    return;
+  return;
 }
 
 function user_import_edit_file_fields(&$form, $import) {
-    
-    $form['filename'] = array(
-        '#type' => 'value',
-        '#value' => $import['filename'],
-    );
-    
-    $form['oldfilename'] = array(
-        '#type' => 'value',
-        '#value' => $import['oldfilename'],
-    );
-    
-    $form['filepath'] = array(
-        '#type' => 'value',
-        '#value' => $import['filepath'],
-    );
-    
-    return;
+
+  $form['filename'] = array(
+    '#type' => 'value',
+    '#value' => $import['filename'],
+  );
+
+  $form['oldfilename'] = array(
+    '#type' => 'value',
+    '#value' => $import['oldfilename'],
+  );
+
+  $form['filepath'] = array(
+    '#type' => 'value',
+    '#value' => $import['filepath'],
+  );
+
+  return;
 }
 
 // - - - - - - - -  FILE HANDLING - - - - - - - -
-
 /**
- * open file
+ * Open file.
  */
 function _user_import_file_open($filepath, $filename) {
-   
-  ini_set('auto_detect_line_endings', true);
+
+  ini_set('auto_detect_line_endings', TRUE);
   $handle = @fopen($filepath, "r");
-                    
+
   if (!$handle) {
     form_set_error('file', t("Could not find the csv file '%filename'", array('%filename' => $filename)), 'error');
-    return t("Please add your file again."); 
+    return t("Please add your file again.");
   }
 
-  return $handle; 
+  return $handle;
 }
 
 function _user_import_file_deletion($filepath, $filename, $old_filename, $ftp, $message = TRUE) {
 
   if ($ftp) {
     drupal_set_message(t("File '%filename' was uploaded using FTP and should be deleted manually once the import has been completed.", array('%filename' => $filename)));
-    return; 
-  } 
-  
+    return;
+  }
+
   $removed = file_delete($filepath);
 
-  if (!$message) return;
+  if (!$message) {
+    return;
+  }
 
   if (empty($removed)) {
-      drupal_set_message(t("File error: file '%old_filename' (%filename) could not be deleted.", array('%old_filename' => $oldfilename, '%filename' => $filename)), 'error');
-  } 
+    drupal_set_message(t("File error: file '%old_filename' (%filename) could not be deleted.", array('%old_filename' => $oldfilename, '%filename' => $filename)), 'error');
+  }
   else {
-      drupal_set_message(t("File '%old_filename' was deleted.", array('%old_filename' => $old_filename)));
+    drupal_set_message(t("File '%old_filename' was deleted.", array('%old_filename' => $old_filename)));
   }
 
-  return; 
+  return;
 }
 
 /*
@@ -652,107 +681,128 @@ function _user_import_file_deletion($filepath, $filename, $old_filename, $ftp, $
  * $ftp_file - chosen from FTP uploaded files
  * $uploaded_file - uploaded through browser
  */
-function _user_import_file($import_id = NULL, $ftp_file_selected = NULL) { 
+function _user_import_file($import_id = NULL, $ftp_file_selected = NULL) {
 
-    static $file;
-    if (!empty($file)) return $file;
-    
-    // file was uploaded through browser
-    $file = file_save_upload('file_upload');
-    if (!empty($file) ) return $file;
-    
-    // file was uploaded by FTP
-    if (!empty($ftp_file_selected)) { 
-        $ftp_files = _user_import_ftp_files();
-        $filepath = drupal_get_path('module', 'user_import');
-        $filename = $ftp_files[$ftp_file_selected];
-        $file = new stdClass();
-        $file->filepath = "$filepath/$filename";
-        $file->filename = $filename;
-        return $file;
-    }
-    
-   // use file info stored in database
-   if (!empty($import_id)) {
-        $import = _user_import_settings_select($import_id);
-        $file->filepath = $import['filepath'];
-        $file->oldfilename = $import['oldfilename'];
-        $file->filename = $import['filename'];
-        return $file;
-   }
-    
-    return;   
+  static $file;
+  if (!empty($file)) {
+    return $file;
+  }
+
+  // File was uploaded through browser.
+  $file = file_save_upload('file_upload');
+  if (!empty($file)) {
+    return $file;
+  }
+
+  // File was uploaded by FTP.
+  if (!empty($ftp_file_selected)) {
+    $ftp_files = _user_import_ftp_files();
+    $filepath = drupal_get_path('module', 'user_import');
+    $filename = $ftp_files[$ftp_file_selected];
+    $file = new stdClass();
+    $file->filepath = "$filepath/$filename";
+    $file->filename = $filename;
+    return $file;
+  }
+
+  // Use file info stored in database.
+  if (!empty($import_id)) {
+    $import = _user_import_settings_select($import_id);
+    $file->filepath = $import['filepath'];
+    $file->oldfilename = $import['oldfilename'];
+    $file->filename = $import['filename'];
+    return $file;
+  }
+
+  return;
 }
 
-// get info on files  uploaded via FTP
+// Get info on files  uploaded via FTP.
 function _user_import_ftp_files() {
-  
-  $directory = opendir( drupal_get_path('module', 'user_import') );
+
+  $directory = opendir(drupal_get_path('module', 'user_import'));
   $filenames[] = t('none');
-	$ignorable_files = array('.', '..', '.DS_Store', 'CVS', '.svn', '.git', 'user_import.test', 'API.txt', 'user_import.drush.inc', 
-													 'README.txt', 'LICENSE.txt', 'UPDATES.txt', 'user_import.module', 'user_import.install', 'user_import.info', 
-													 'user_import.admin.inc', 'user_import.import.inc', 'supported', 'tests');
-  
+  $ignorable_files = array(
+    '.',
+    '..',
+    '.DS_Store',
+    'CVS',
+    '.svn',
+    '.git',
+    'user_import.test',
+    'API.txt',
+    'user_import.drush.inc',
+    'README.txt',
+    'LICENSE.txt',
+    'UPDATES.txt',
+    'user_import.module',
+    'user_import.install',
+    'user_import.info',
+    'user_import.admin.inc',
+    'user_import.import.inc',
+    'supported',
+    'tests',
+  );
+
   while ($file = readdir($directory)) {
-    if (!in_array($file, $ignorable_files)) { 
-	  	$filenames[] = $file;
-		} 
+    if (!in_array($file, $ignorable_files)) {
+      $filenames[] = $file;
+    }
   }
-  
+
   closedir($directory);
   return $filenames;
 }
 
-// delete incomplete import settings, where only the file has been uploaded
-function  _user_import_incomplete_deletion() {
+// Delete incomplete import settings, where only the file has been uploaded.
+function _user_import_incomplete_deletion() {
 
   $results = db_query("SELECT * FROM {user_import} WHERE setting = 'file set'");
 
   while ($import = db_fetch_object($results)) {
     $options = unserialize($import->options);
     _user_import_file_deletion($import->filepath, $import->filename, $import->oldfilename, $options['ftp'], FALSE);
-    _user_import_settings_deletion($import->import_id); 
+    _user_import_settings_deletion($import->import_id);
   }
 
-  return;   
+  return;
 }
 
-// - - - - - - - -  MISC - - - - - - - - 
-
+// - - - - - - - -  MISC - - - - - - - -
 function user_import_form_field_match(&$form, $import) {
 
-	$delimiter = isset($import['options']['delimiter']) && !empty($import['options']['delimiter']) ? $import['options']['delimiter'] : ',';
+  $delimiter = isset($import['options']['delimiter']) && !empty($import['options']['delimiter']) ? $import['options']['delimiter'] : ',';
   $collapsed = (empty($import['name'])) ? FALSE: TRUE;
   $handle = _user_import_file_open($form['filepath']['#value'], $form['filename']['#value']);
   $data_row = _user_import_file_row($form['filename']['#value'], $handle, $delimiter);
 
   $fieldmatch_description_parts = array(
-		'<strong>'. t('Drupal fields') .':</strong> '. t("Match columns in CSV file to drupal user fields, leave as '----' to ignore the column."),
-		'<strong>'. t('Username') .':</strong> '. t("If username is selected for multiple fields, the username will be built in the order selected. Otherwise, the username will be randomly generated."),
-		'<strong>'. t('Abbreviate') .':</strong> '. t("Use the first letter of a field in uppercase for the Username, e.g. 'john' -> 'J'."), 
+    '<strong>' . t('Drupal fields') . ':</strong> ' . t("Match columns in CSV file to drupal user fields, leave as '----' to ignore the column."),
+    '<strong>' . t('Username') . ':</strong> ' . t("If username is selected for multiple fields, the username will be built in the order selected. Otherwise, the username will be randomly generated."),
+    '<strong>' . t('Abbreviate') . ':</strong> ' . t("Use the first letter of a field in uppercase for the Username, e.g. 'john' -> 'J'."),
   );
 
   $fieldmatch_description = theme('item_list', $fieldmatch_description_parts);
-  
+
   $form['field_match'] = array(
-      '#type' => 'fieldset',
-      '#title' => t('Field Match'),
-      '#description' => $fieldmatch_description,
-      '#weight' => -90,
-      '#collapsible' => TRUE,
-      '#collapsed' => $collapsed, 
-      '#tree' => TRUE,
+    '#type' => 'fieldset',
+    '#title' => t('Field Match'),
+    '#description' => $fieldmatch_description,
+    '#weight' => -90,
+    '#collapsible' => TRUE,
+    '#collapsed' => $collapsed,
+    '#tree' => TRUE,
   );
 
-  // add default and email address options
+  // Add default and email address options.
   $user_fields[0] = '-------------';
   $additional_user_fields = module_invoke_all('user_import_form_field_match');
- 
+
   foreach ($additional_user_fields as $type => $type_options) {
     if (is_array($type_options)) {
       foreach ($type_options as $field_id => $label) {
         $user_fields["$type-$field_id"] = $label;
-      } 
+      }
     }
   }
 
@@ -760,155 +810,162 @@ function user_import_form_field_match(&$form, $import) {
 
   $row = 0;
   $sort = array(t('--'), 1, 2, 3, 4);
-  
-  if (empty($data_row)) return; 
-    
-  foreach ($data_row as $data_cell) {        
-
-      $form['field_match'][$row]= array(
-          '#tree' => TRUE,
-      );
- 
-      $form['field_match'][$row]['csv'] = array( 
-          '#value' => check_plain(drupal_substr($data_cell, 0, 40)),
-      );
-  
-      $form['field_match'][$row]['field_match'] = array( 
-          '#type' => 'select',
-          '#default_value' => isset($import['field_match'][$row]['field_match']) ? $import['field_match'][$row]['field_match'] : $user_fields[0],
-          '#options' => $user_fields,
-      );
-
-      $form['field_match'][$row]['username'] = array( 
-          '#type' => 'select',
-          '#default_value' => isset($import['field_match'][$row]['username']) ? $import['field_match'][$row]['username'] : $sort[0],
-          '#options' => $sort,
-      );
-      
-      $form['field_match'][$row]['abbreviate'] = array( 
-          '#type' => 'checkbox',
-          '#default_value' => isset($import['field_match'][$row]['abbreviate']) ? $import['field_match'][$row]['abbreviate'] : NULL,
-      );
-
-      $row++;
+
+  if (empty($data_row)) {
+    return;
+  }
+
+  foreach ($data_row as $data_cell) {
+
+    $form['field_match'][$row] = array(
+      '#tree' => TRUE,
+    );
+
+    $form['field_match'][$row]['csv'] = array(
+      '#value' => check_plain(drupal_substr($data_cell, 0, 40)),
+    );
+
+    $form['field_match'][$row]['field_match'] = array(
+      '#type' => 'select',
+      '#default_value' => isset($import['field_match'][$row]['field_match']) ? $import['field_match'][$row]['field_match'] : $user_fields[0],
+      '#options' => $user_fields,
+    );
+
+    $form['field_match'][$row]['username'] = array(
+      '#type' => 'select',
+      '#default_value' => isset($import['field_match'][$row]['username']) ? $import['field_match'][$row]['username'] : $sort[0],
+      '#options' => $sort,
+    );
+
+    $form['field_match'][$row]['abbreviate'] = array(
+      '#type' => 'checkbox',
+      '#default_value' => isset($import['field_match'][$row]['abbreviate']) ? $import['field_match'][$row]['abbreviate'] : NULL,
+    );
+
+    $row++;
   }
- 
+
   return;
 }
 
-// get first row of file
+// Get first row of file.
 function _user_import_file_row($filename, $handle, $delimiter = ',') {
 
-	// Handle folks who may list 'tab' as 't' or 'tab'
-	if (strtolower($delimiter) == 't' || strtolower($delimiter) == 'tab') {
-		$delimiter = '\t';	
-	}
-	
-	$data_row = @fgetcsv ($handle, 1000000, $delimiter);
-	
-	if (!$data_row) {
-	    form_set_error('file', t("Could not get data, the file '%filename' is either empty or has incompatible line endings.", array('%filename' => $filename)), 'error');
-	}
-	return $data_row; 
+  // Handle folks who may list 'tab' as 't' or 'tab.'
+  if (strtolower($delimiter) == 't' || strtolower($delimiter) == 'tab') {
+    $delimiter = '\t';
+  }
+
+  $data_row = @fgetcsv($handle, 1000000, $delimiter);
+
+  if (!$data_row) {
+    form_set_error('file', t("Could not get data, the file '%filename' is either empty or has incompatible line endings.", array('%filename' => $filename)), 'error');
+  }
+  return $data_row;
 }
 
-// move from one stage to the next
-// set up all necessary variables
+// Move from one stage to the next.
+// Set up all necessary variables.
 function _user_import_initialise_import($import) {
 
-	//_user_import_process won't work w/o this include
-	module_load_include('inc', 'user_import', 'user_import.import');
-	
-	switch ($import['setting']) {
-	  case 'imported':
-	      drupal_set_message(t('File has already been imported'), 'error');
-	      break;
+  // _user_import_process won't work w/o this include.
+  module_load_include('inc', 'user_import', 'user_import.import');
 
-	  // add setting template values to new import settings
-	  case 'file set':
-	      if (empty($import['template_id'])) return $import;
-	      $template  = _user_import_settings_select($import['template_id']);
-	      $template['import_id'] = $import['import_id'];
-	      $template['filename'] = $import['filename'];
-	      $template['oldfilename'] = $import['oldfilename'];
-	      $template['filepath'] = $import['filepath'];
-	      $template['started'] = 0;
-	      $template['setting'] = 'file set';
-	      return $template;
-     
-	  case 'test':
-	  case 'tested':
-	      $import['setting'] = 'import';
-	      $import['started'] = 0;
-	      $import['pointer'] = 0;
-	      $import['processed'] = 0;
-	      $import['valid'] = 0;
-	      _user_import_errors_display_delete($import['import_id']);
-	      _user_import_settings_save($import);
-	      _user_import_process($import);
-	      break;
-     
-	  case 'template':
-	      unset($import['filename']);
-	      unset($import['oldfilename']);
-	      unset($import['filepath']);
-	      $import['started'] = 0;
-	      $import['pointer'] = 0;
-	      $import['processed'] = 0;
-	      $import['valid'] = 0;
-	      _user_import_settings_save($import);
-	      break;
-     
-	  default:
-	      _user_import_process($import);
-	      drupal_set_message(t('Imported'));
-	      break;
-	}
+  switch ($import['setting']) {
+    case 'imported':
+      drupal_set_message(t('File has already been imported'), 'error');
+      break;
 
-	return;
+    // Add setting template values to new import settings.
+    case 'file set':
+      if (empty($import['template_id'])) {
+        return $import;
+      }
+      $template = _user_import_settings_select($import['template_id']);
+      $template['import_id'] = $import['import_id'];
+      $template['filename'] = $import['filename'];
+      $template['oldfilename'] = $import['oldfilename'];
+      $template['filepath'] = $import['filepath'];
+      $template['started'] = 0;
+      $template['setting'] = 'file set';
+      return $template;
+
+    case 'test':
+    case 'tested':
+      $import['setting'] = 'import';
+      $import['started'] = 0;
+      $import['pointer'] = 0;
+      $import['processed'] = 0;
+      $import['valid'] = 0;
+      _user_import_errors_display_delete($import['import_id']);
+      _user_import_settings_save($import);
+      _user_import_process($import);
+      break;
+
+    case 'template':
+      unset($import['filename']);
+      unset($import['oldfilename']);
+      unset($import['filepath']);
+      $import['started'] = 0;
+      $import['pointer'] = 0;
+      $import['processed'] = 0;
+      $import['valid'] = 0;
+      _user_import_settings_save($import);
+      break;
+
+    default:
+      _user_import_process($import);
+      drupal_set_message(t('Imported'));
+      break;
+  }
+  return;
 }
 
 function _user_import_errors_display_delete($import_id) {
 
-	db_query("DELETE FROM {user_import_errors} WHERE import_id = %d", $import_id);
-	return; 
+  db_query("DELETE FROM {user_import_errors} WHERE import_id = %d", $import_id);
+  return;
 }
 
 function _user_import_profile($key = 'fid', $return_value = NULL) {
-    
-    if (!module_exists('profile')) return; 
-    
-    static $fields_static;
-		$fields = array();
-    
-    // avoid making more than one database call for profile info
-    if (empty($fields_static)) {
-    
-        $results = db_query("SELECT * FROM {profile_fields}");
-                
-        while ($row = db_fetch_object($results)) { 
-            // don't include private fields
-            if (user_access('administer users') || $row->visibility != PROFILE_PRIVATE) {
-                $fields_static[] = $row;
-            }
-        }
+
+  if (!module_exists('profile')) {
+    return;
+  }
+
+  static $fields_static;
+  $fields = array();
+
+  // Avoid making more than one database call for profile info.
+  if (empty($fields_static)) {
+
+    $results = db_query("SELECT * FROM {profile_fields}");
+
+    while ($row = db_fetch_object($results)) {
+      // Don't include private fields.
+      if (user_access('administer users') || $row->visibility != PROFILE_PRIVATE) {
+        $fields_static[] = $row;
+      }
     }
+  }
 
-    if (empty($fields_static)) return array();
-   
-    // return all profile fields info, or just specific type
-    if (empty($return_value)) {
-        
-        foreach ($fields_static as $field) {
-            $fields[$field->{$key}] = $field;
-        }
-    } 
-    else {
-        foreach ($fields_static as $field) {
-            $fields[$field->{$key}] = $field->{$return_value};
-        }
+  if (empty($fields_static)) {
+    return array();
+  }
+
+  // Return all profile fields info, or just specific type.
+  if (empty($return_value)) {
+
+    foreach ($fields_static as $field) {
+      $fields[$field->{$key}] = $field;
     }
-    
-    asort($fields);    
-    return $fields;
-}
\ No newline at end of file
+  }
+  else {
+    foreach ($fields_static as $field) {
+      $fields[$field->{$key}] = $field->{$return_value};
+    }
+  }
+
+  asort($fields);
+  return $fields;
+}
diff --git a/user_import.drush.inc b/user_import.drush.inc
index 745234e..bff5795 100644
--- a/user_import.drush.inc
+++ b/user_import.drush.inc
@@ -58,7 +58,7 @@ function drush_user_import_user_import($original_file = NULL, $template_name = N
   $file->filename = basename($original_file);
   file_copy($file, file_directory_temp(), FILE_EXISTS_RENAME);
   $import = new stdClass();
-  // initialize import from template
+  // Initialize import from template.
   $import->first_line_skip = $template->first_line_skip;
   $import->contact = $template->contact;
   $import->username_space = $template->username_space;
diff --git a/user_import.import.inc b/user_import.import.inc
index ba435fc..39511c3 100644
--- a/user_import.import.inc
+++ b/user_import.import.inc
@@ -1,225 +1,244 @@
 <?php
 
-function _user_import_process($settings) {  
-  // Load supported modules
+function _user_import_process($settings) {
+  // Load supported modules.
   user_import_load_supported();
 
-	$remaining_data = FALSE;
-	$line_max = variable_get('user_import_line_max', 1000);
-	$import_max = variable_get('user_import_max', 250);
-	$field_match = _user_import_unconcatenate_field_match($settings['field_match']);
-	$update_setting = _user_import_update_user_check($settings['options']['update_user']);
-	$update_setting_per_module = $settings['options']['update_user'];
-	$username_data = array();
-	$username_order = array();
-	$username_abbreviate = array();
-	$first_line_skip = 0;
+  $remaining_data = FALSE;
+  $line_max = variable_get('user_import_line_max', 1000);
+  $import_max = variable_get('user_import_max', 250);
+  $field_match = _user_import_unconcatenate_field_match($settings['field_match']);
+  $update_setting = _user_import_update_user_check($settings['options']['update_user']);
+  $update_setting_per_module = $settings['options']['update_user'];
+  $username_data = array();
+  $username_order = array();
+  $username_abbreviate = array();
+  $first_line_skip = 0;
   $delimiter = isset($settings['delimiter']) && !empty($settings['delimiter']) ? $settings['delimiter'] : ',';
 
-	ini_set('auto_detect_line_endings', TRUE);
-	$handle = @fopen($settings['filepath'], "r");
+  ini_set('auto_detect_line_endings', TRUE);
+  $handle = @fopen($settings['filepath'], "r");
 
-	// move pointer to where test/import last finished
-	if ($settings['pointer'] != 0) fseek ($handle, $settings['pointer']);
+  // Move pointer to where test/import last finished.
+  if ($settings['pointer'] != 0) {
+    fseek($handle, $settings['pointer']);
+  }
+
+  // Start count of imports on this cron run.
+  $processed_counter = 0;
 
-	// start count of imports on this cron run
-	$processed_counter = 0;
-   
   while ($data = fgetcsv($handle, $line_max, $delimiter)) {
-    
-		$errors = user_import_errors(FALSE, TRUE);
-
-		// if importing, check we are not over max number of imports per cron
-		if ($settings['setting'] == 'import' && $processed_counter >= $import_max) {
-	    $remaining_data = TRUE;
-	    break;
-		}
-
-		// don't process empty lines
-		$line_filled = (count($data) == 1 && drupal_strlen($data[0]) == 0) ? FALSE : TRUE;
-
-		if ($line_filled) {
-
-		    // check if this is first line - if so should we skip?
-		    if (!empty($settings['first_line_skip']) && $settings['processed'] == 0) {
-	        // reset to false on second process
-	        $first_line_skip = (empty($first_line_skip)) ? TRUE : FALSE;
-		    }
-
-		    if (!$first_line_skip) {
-
-		        unset($errors, $fields);
-		        reset($field_match);
-		        $password = '';
-             
-            // Process data cell.
-		        foreach ($field_match as $column_id => $column_settings) {
-
-		          $type = $column_settings['type'];
-		          $field_id = $column_settings['field_id'];
-
-		          // Skip if this is a field used as part of a username but
-		          // not otherwise mapped for import.
-		          if ($type != 'username_part') {
-		            $fields[$type][$field_id] = module_invoke_all('user_import_data', $settings, $update_setting, $column_settings, $type, $field_id, $data, $column_id);
-		          }
-		          // Read in data if present for concatenating a user name.
-		          if ($column_settings['username'] > 0) {
-                
-		            $username_data[$column_id] = $data[$column_id];
-		            $username_order[$column_id] = $column_settings['username'];
-		            $username_abbreviate[$column_id]= $column_settings['abbreviate']; 
-		          }
-		        }
-
-		        $errors = user_import_errors();
-		        $account = array();
-		        $existing_account = FALSE;
-		        $updated = FALSE;
-
-		        // if we update existing users matched by email (and therefore passed validation even if this email already exists)
-		        // look for and use an existing account.
-		        if ($update_setting && !empty($fields['user']['email'][0])) {
-		          $existing_account = user_load(array('mail' => $fields['user']['email'][0]));
-		          if ($existing_account) $account = (array) $existing_account; 
-		        }
-       
-		        // if $account['uid'] is not empty then we can assume the account is being updated
-		        $account_additions = module_invoke_all('user_import_pre_save', $settings, $account, $fields, $errors, $update_setting_per_module);
-
-		        foreach($account_additions as $field_name => $value) {
-		          $account[$field_name] = $value;
-		        }
-
-		        if (empty($errors)) {
-
-		           if ($settings['setting'] == 'import') {
-
-		             if ($existing_account) {  
-		               $account = user_save($existing_account, $account);
-		               $updated = TRUE;
-		             }
-		             else {
-		               // Only set a user name if we are not updating an existing record.
-		               $account['name'] = _user_import_create_username($username_order, $username_data, $username_abbreviate, $settings['username_space']);
-		               $password = $account['pass'];
-		               $account = user_save('', $account);
-		             } 
-
-		             module_invoke_all('user_import_after_save', $settings, $account, $password, $fields, $updated, $update_setting_per_module);
-		             $processed_counter++; 
-		           }
-              $settings['processed']++;
-		          $settings['valid']++; 
-		        }
-    
-		        
-		    }
-		
-		    $settings['pointer'] = ftell($handle);
-
-		    // save lines that have fatal errors
-		    if (!empty($errors)) {
-		      $account_email = isset($account['email']) ? $account['email'] : '';
-		      _user_import_errors_display_save($settings['import_id'], $fields, $account_email, $errors);
-		    }
-		}
-
-		$settings['setting'] = _user_import_save_progress($settings['setting'], $remaining_data, $settings['pointer'], $settings['processed'], $settings['valid'], $settings['import_id']);
+
+    $errors = user_import_errors(FALSE, TRUE);
+
+    // If importing, check we are not over max number of imports per cron.
+    if ($settings['setting'] == 'import' && $processed_counter >= $import_max) {
+      $remaining_data = TRUE;
+      break;
+    }
+
+    // Don't process empty lines.
+    $line_filled = (count($data) == 1 && drupal_strlen($data[0]) == 0) ? FALSE : TRUE;
+
+    if ($line_filled) {
+
+      // Check if this is first line - if so should we skip?
+      if (!empty($settings['first_line_skip']) && $settings['processed'] == 0) {
+        // Reset to false on second process.
+        $first_line_skip = (empty($first_line_skip)) ? TRUE : FALSE;
+      }
+
+      if (!$first_line_skip) {
+
+        unset($errors, $fields);
+        reset($field_match);
+        $password = '';
+
+        // Process data cell.
+        foreach ($field_match as $column_id => $column_settings) {
+
+          $type = $column_settings['type'];
+          $field_id = $column_settings['field_id'];
+
+          // Skip if this is a field used as part of a username but
+          // not otherwise mapped for import.
+          if ($type != 'username_part') {
+            $fields[$type][$field_id] = module_invoke_all('user_import_data', $settings, $update_setting, $column_settings, $type, $field_id, $data, $column_id);
+          }
+          // Read in data if present for concatenating a user name.
+          if ($column_settings['username'] > 0) {
+
+            $username_data[$column_id] = $data[$column_id];
+            $username_order[$column_id] = $column_settings['username'];
+            $username_abbreviate[$column_id] = $column_settings['abbreviate'];
+          }
+        }
+
+        $errors = user_import_errors();
+        $account = array();
+        $existing_account = FALSE;
+        $updated = FALSE;
+
+        // If we update existing users matched by email (and therefore passed
+        // validation even if this email already exists).
+        // look for and use an existing account.
+        if ($update_setting && !empty($fields['user']['email'][0])) {
+          $existing_account = user_load(array('mail' => $fields['user']['email'][0]));
+          if ($existing_account) {
+            $account = (array) $existing_account;
+          }
+        }
+
+        // If $account['uid'] is not empty then we can assume
+        // the account is being updated.
+        $account_additions = module_invoke_all('user_import_pre_save', $settings, $account, $fields, $errors, $update_setting_per_module);
+
+        foreach ($account_additions as $field_name => $value) {
+          $account[$field_name] = $value;
+        }
+
+        if (empty($errors)) {
+
+          if ($settings['setting'] == 'import') {
+
+            if ($existing_account) {
+              $account = user_save($existing_account, $account);
+              $updated = TRUE;
+            }
+            else {
+              // Only set a user name if we are not updating an existing record.
+              $account['name'] = _user_import_create_username($username_order, $username_data, $username_abbreviate, $settings['username_space']);
+              $password = $account['pass'];
+              $account = user_save('', $account);
+            }
+
+            module_invoke_all('user_import_after_save', $settings, $account, $password, $fields, $updated, $update_setting_per_module);
+            $processed_counter++;
+          }
+          $settings['processed']++;
+          $settings['valid']++;
+        }
+
+      }
+
+      $settings['pointer'] = ftell($handle);
+
+      // Save lines that have fatal errors.
+      if (!empty($errors)) {
+        $account_email = isset($account['email']) ? $account['email'] : '';
+        _user_import_errors_display_save($settings['import_id'], $fields, $account_email, $errors);
+      }
+    }
+
+    $settings['setting'] = _user_import_save_progress($settings['setting'], $remaining_data, $settings['pointer'], $settings['processed'], $settings['valid'], $settings['import_id']);
 
   }
 
-	// Save progress.
-	$settings['setting'] = _user_import_save_progress($settings['setting'], $remaining_data, $settings['pointer'], $settings['processed'], $settings['valid'], $settings['import_id'], TRUE);
-    
-  fclose ($handle);
+  // Save progress.
+  $settings['setting'] = _user_import_save_progress($settings['setting'], $remaining_data, $settings['pointer'], $settings['processed'], $settings['valid'], $settings['import_id'], TRUE);
+
+  fclose($handle);
   return $settings;
 }
 
-// errors for user being imported
+// Errors for user being imported.
 function user_import_errors($error = FALSE, $clear = FALSE) {
 
   static $errors = array();
-  if ($clear) $errors = array();
-  if ($error) $errors[] = $error;
+  if ($clear) {
+    $errors = array();
+  }
+  if ($error) {
+    $errors[] = $error;
+  }
   return $errors;
 }
 
 function _user_import_create_username($order, $data, $abbreviate, $username_space) {
 
   $username = '';
-	 
-	if (is_array($order)) {
 
-	  asort($order);
-	  //reset($order);
+  if (is_array($order)) {
 
+    asort($order);
 
-	  //while (list ($file_column, $sequence) = each ($order)) {
     foreach ($order as $file_column => $sequence) {
 
-	    if (!empty($username) && !empty($username_space)) {
-	      $username .= ' ';
-	    }
-	
-	    if ($abbreviate[$file_column] == 1) {
-		    //$username .= trim(drupal_strtoupper(chr(ord($data[$file_column]))));
-		    $first_character = trim($data[$file_column]);
-		    $first_character = drupal_substr($first_character, 0, 1);
-        $username .= drupal_strtoupper($first_character);	
-	    }
-	    else {
-		    $username .= trim($data[$file_column]);
-	    } 
+      if (!empty($username) && !empty($username_space)) {
+        $username .= ' ';
+      }
 
-	  }
-	}
+      if ($abbreviate[$file_column] == 1) {
 
-	if (empty($username)) $username = _user_import_random_username();
+        $first_character = trim($data[$file_column]);
+        $first_character = drupal_substr($first_character, 0, 1);
+        $username .= drupal_strtoupper($first_character);
+      }
+      else {
+        $username .= trim($data[$file_column]);
+      }
 
-	$username = _user_import_sanitise_username($username);
-	$username = _user_import_unique_username($username, TRUE);
-	return $username;
+    }
+  }
+
+  if (empty($username)) {
+    $username = _user_import_random_username();
+  }
+
+  $username = _user_import_sanitise_username($username);
+  $username = _user_import_unique_username($username, TRUE);
+  return $username;
 }
 
 /**
- *  conform to Drupal username rules
+ * Conform to Drupal username rules.
  */
 function _user_import_sanitise_username($username) {
-  
-  // username cannot contain an illegal character 
+
+  // Username cannot contain an illegal character.
   $username = preg_replace('/[^\x80-\xF7 [:alnum:]@_.-]/', '', $username);
   $username = preg_replace(
-    '/[\x{80}-\x{A0}'.          // Non-printable ISO-8859-1 + NBSP
-    '\x{AD}'.                 // Soft-hyphen
-    '\x{2000}-\x{200F}'.      // Various space characters
-    '\x{2028}-\x{202F}'.      // Bidirectional text overrides
-    '\x{205F}-\x{206F}'.      // Various text hinting characters
-    '\x{FEFF}'.               // Byte order mark
-    '\x{FF01}-\x{FF60}'.      // Full-width latin
-    '\x{FFF9}-\x{FFFD}'.      // Replacement characters
+    // Non-printable ISO-8859-1 + NBSP.
+    '/[\x{80}-\x{A0}' .
+    // Soft-hyphen.
+    '\x{AD}' .
+    // Various space characters.
+    '\x{2000}-\x{200F}' .
+    // Bidirectional text overrides.
+    '\x{2028}-\x{202F}' .
+    // Various text hinting characters.
+    '\x{205F}-\x{206F}' .
+    // Byte order mark.
+    '\x{FEFF}' .
+    // Full-width latin.
+    '\x{FF01}-\x{FF60}' .
+    // Replacement characters.
+    '\x{FFF9}-\x{FFFD}' .
+    // Everything else.
     '\x{0}]/u',
-    '', $username); 
-  
-  // username cannot contain multiple spaces in a row
-  $username = preg_replace('/[ ]+/', ' ', $username);   
+    '', $username);
 
-  // username must be less than 56 characters
+  // Username cannot contain multiple spaces in a row.
+  $username = preg_replace('/[ ]+/', ' ', $username);
+
+  // Username must be less than 56 characters.
   $username = substr($username, 0, 56);
 
-  // username cannot begin or end with a space
-  $username = trim($username); 
+  // Username cannot begin or end with a space.
+  $username = trim($username);
   return $username;
 }
 
 /**
- *  deal with duplicate usernames 
+ * Deal with duplicate usernames.
  */
 function _user_import_unique_username($username, $start = FALSE) {
 
   static $suffix = 1;
-  if ($start) $suffix = 1;
-  
+  if ($start) {
+    $suffix = 1;
+  }
+
   if ($suffix < 2) {
     $duplicate = db_result(db_query("SELECT uid from {users} where name = '%s' LIMIT 1", $username));
   }
@@ -227,84 +246,91 @@ function _user_import_unique_username($username, $start = FALSE) {
     $duplicate = db_result(db_query("SELECT uid from {users} where name = '%s' LIMIT 1", "$username $suffix"));
   }
 
-  // loop until name is valid 
+  // Loop until name is valid.
   if (!empty($duplicate)) {
     $suffix++;
     _user_import_unique_username($username);
   }
-  
-  // add number at end of username if it already exists
+
+  // Add number at end of username if it already exists.
   $username = ($suffix < 2) ? $username : "$username $suffix";
 
   return $username;
 }
 
-// Update settings for existing import 
+// Update settings for existing import.
 function _user_import_settings_update($pointer, $processed, $valid, $setting, $import_id) {
 
-  if (empty($import_id)) return;
+  if (empty($import_id)) {
+    return;
+  }
   db_query("UPDATE {user_import} SET pointer = %d, processed = %d, valid= %d, setting = '%s' WHERE import_id = %d", $pointer, $processed, $valid, $setting, $import_id);
 }
 
 function _user_import_random_username() {
-    $username = '';
-    $vowels = 'aoueiy';
-    $consonants = 'bcdfghjklmnpqrstvwxz';
-    $length = 8;
-    
-    mt_srand ((double) microtime() * 10000000);
-    $next_vowel = 0;
-    
-    for ($count = 0; $count <= $length; $count++) {
+  $username = '';
+  $vowels = 'aoueiy';
+  $consonants = 'bcdfghjklmnpqrstvwxz';
+  $length = 8;
+
+  mt_srand((double) microtime() * 10000000);
+  $next_vowel = 0;
+
+  for ($count = 0; $count <= $length; $count++) {
+
+    if ($next_vowel) {
+      $rand = mt_rand(0, 5);
+      $username .= $vowels{$rand};
+      $next_vowel = 0;
 
-        if ($next_vowel) {
-            $rand = mt_rand(0, 5);
-            $username.= $vowels{$rand};
-            $next_vowel = 0;
-    
-        } 
-        else {
-            $rand = mt_rand(0, 19);
-            $username .= $consonants{$rand};
-            $next_vowel = 1;
-        }
     }
-    
-    return $username;
+    else {
+      $rand = mt_rand(0, 19);
+      $username .= $consonants{$rand};
+      $next_vowel = 1;
+    }
+  }
+
+  return $username;
 }
 
-// check if any updates are to be made
+// Check if any updates are to be made.
 function _user_import_update_user_check($settings) {
 
   foreach ($settings as $setting) {
-    if ($setting != UPDATE_NONE) return TRUE;
+    if ($setting != UPDATE_NONE) {
+      return TRUE;
+    }
   }
-  
+
   return FALSE;
 }
 
 function _user_import_errors_display_save($import_id, $data, $email, $errors) {
 
-	$data['email'] = $email;
+  $data['email'] = $email;
 
-	db_query("INSERT INTO {user_import_errors} 
-				   (import_id, data, errors) 
-				   VALUES (%d, '%s', '%s')
-				   ", $import_id, serialize($data), serialize($errors));
-	return;
+  db_query("INSERT INTO {user_import_errors}
+           (import_id, data, errors)
+           VALUES (%d, '%s', '%s')
+           ", $import_id, serialize($data), serialize($errors));
+  return;
 }
 
 /**
- *  Save progress status and counter of the import.
+ * Save progress status and counter of the import.
  */
 function _user_import_save_progress($status, $remaining_data, $pointer, $processed, $valid, $import_id, $status_check = FALSE) {
-	
+
   if ($status_check) {
-	  if ($status == 'import' && !$remaining_data) $status = 'imported';
-	  if ($status == 'test') $status = 'tested';
+    if ($status == 'import' && !$remaining_data) {
+      $status = 'imported';
+    }
+    if ($status == 'test') {
+      $status = 'tested';
+    }
   }
 
   _user_import_settings_update($pointer, $processed, $valid, $status, $import_id);
-  return $status;	
+  return $status;
 }
-
diff --git a/user_import.info b/user_import.info
index 75562a7..eb72818 100644
--- a/user_import.info
+++ b/user_import.info
@@ -1,7 +1,3 @@
 name = User Import
 description = Import users into Drupal from a CSV file.
-core = 6.x 
-
-
-
-
+core = 6.x
diff --git a/user_import.install b/user_import.install
index e6c13e0..ebde1ef 100644
--- a/user_import.install
+++ b/user_import.install
@@ -1,12 +1,11 @@
 <?php
-
 /**
- * @file 
+ * @file
  * Import and update users from a comma separated file (csv).
  */
 
 /**
- * Implementation of hook_install()
+ * Implements hook_install().
  */
 function user_import_install() {
   // Create tables.
@@ -15,140 +14,140 @@ function user_import_install() {
 }
 
 /**
-* Implementation of hook_schema(). 
-*/
+ * Implements hook_schema().
+ */
 function user_import_schema() {
   $schema['user_import'] = array(
-     'description' => t("Settings for each import, and import setting templates."),
-     'fields' => array(
-        'import_id' => array(
-        'description' => t("ID key of import or template."),
+    'description' => "Settings for each import, and import setting templates.",
+    'fields' => array(
+      'import_id' => array(
+        'description' => "ID key of import or template.",
         'type' => 'serial',
         'unsigned' => TRUE,
         'not null' => TRUE,
-        'disp-width' => '10'
+        'disp-width' => '10',
       ),
       'name' => array(
-        'description' => t("Label of import template, only used if this is an import template."),
+        'description' => "Label of import template, only used if this is an import template.",
         'type' => 'varchar',
         'length' => '25',
         'not null' => TRUE,
-        'default' => ''
+        'default' => '',
       ),
-      'filename' => array( 
-        'description' => t("Name of file being used as source of data for import."),
+      'filename' => array(
+        'description' => "Name of file being used as source of data for import.",
         'type' => 'varchar',
         'length' => '50',
         'not null' => TRUE,
-        'default' => ''
+        'default' => '',
       ),
-      'oldfilename' => array( 
-        'description' => t("Original name of file being used as source of data for import."), 
+      'oldfilename' => array(
+        'description' => "Original name of file being used as source of data for import.",
         'type' => 'varchar',
         'length' => '50',
         'not null' => TRUE,
-        'default' => ''
+        'default' => '',
       ),
-      'filepath' => array( 
-        'description' => t("Path to file being used as source of data for import."), 
+      'filepath' => array(
+        'description' => "Path to file being used as source of data for import.",
         'type' => 'text',
         'size' => 'small',
-        'not null' => TRUE
+        'not null' => TRUE,
       ),
-      'started' => array(  
-        'description' => t("Datestamp of when import was started."), 
+      'started' => array(
+        'description' => "Datestamp of when import was started.",
         'type' => 'int',
         'not null' => TRUE,
         'default' => 0,
-        'disp-width' => '11'
+        'disp-width' => '11',
       ),
-      'pointer' => array( 
-        'description' => t("Pointer to where test/import last finished."), 
+      'pointer' => array(
+        'description' => "Pointer to where test/import last finished.",
         'type' => 'int',
         'not null' => TRUE,
         'default' => 0,
-        'disp-width' => '10'
+        'disp-width' => '10',
       ),
-      'processed' => array(  
-        'description' => t("Number of users processed by import."), 
+      'processed' => array(
+        'description' => "Number of users processed by import.",
         'type' => 'int',
         'not null' => TRUE,
         'default' => 0,
-        'disp-width' => '10'
+        'disp-width' => '10',
       ),
-      'valid' => array(    
-        'description' => t("Number of users processed without errors."), 
+      'valid' => array(
+        'description' => "Number of users processed without errors.",
         'type' => 'int',
         'not null' => TRUE,
         'default' => 0,
-        'disp-width' => '10'
+        'disp-width' => '10',
       ),
-      'field_match' => array( 
-        'description' => t("Settings for how data matches to Drupal fields."), 
+      'field_match' => array(
+        'description' => "Settings for how data matches to Drupal fields.",
         'type' => 'text',
         'size' => 'big',
         'not null' => TRUE,
-        'serialize' => TRUE
+        'serialize' => TRUE,
       ),
-      'roles' => array(      
-        'description' => t("Roles to give imported users."), 
+      'roles' => array(
+        'description' => "Roles to give imported users.",
         'type' => 'text',
         'size' => 'big',
         'not null' => TRUE,
-        'serialize' => TRUE
+        'serialize' => TRUE,
       ),
-      'options' => array(   
-        'description' => t("Store of all other options for import. Most of the other settings in this table will be moved into here in future."), 
+      'options' => array(
+        'description' => "Store of all other options for import. Most of the other settings in this table will be  moved into here in future.",
         'type' => 'text',
         'size' => 'big',
         'not null' => TRUE,
-        'serialize' => TRUE
+        'serialize' => TRUE,
       ),
-      'setting' => array(    
-        'description' => t("Status of import, or whether it is an import template."), 
+      'setting' => array(
+        'description' => "Status of import, or whether it is an import template.",
         'type' => 'varchar',
         'length' => '10',
         'not null' => TRUE,
-        'default' => ''
-      )
+        'default' => '',
+      ),
     ),
     'primary key' => array('import_id'),
   );
 
-  $schema['user_import_errors'] = array(  
-    'description' => t("Record of errors encountered during an import."), 
-    'fields' => array(    
-      'import_id' => array( 
-        'description' => t("ID key of import or template."), 
+  $schema['user_import_errors'] = array(
+    'description' => "Record of errors encountered during an import.",
+    'fields' => array(
+      'import_id' => array(
+        'description' => "ID key of import or template.",
         'type' => 'int',
         'not null' => TRUE,
         'default' => 0,
-        'disp-width' => '10'
+        'disp-width' => '10',
       ),
-      'data' => array(  
-        'description' => t("Data (matched to fields) for user that failed to import due to error."), 
+      'data' => array(
+        'description' => "Data (matched to fields) for user that failed to import due to error.",
         'type' => 'text',
         'size' => 'big',
         'not null' => TRUE,
-        'serialize' => TRUE
+        'serialize' => TRUE,
       ),
-      'errors' => array(  
-        'description' => t("Error(s) encountered for user that failed to import."), 
+      'errors' => array(
+        'description' => "Error(s) encountered for user that failed to import.",
         'type' => 'text',
         'size' => 'big',
         'not null' => TRUE,
-        'serialize' => TRUE
-      )
+        'serialize' => TRUE,
+      ),
     ),
     'indexes' => array(
-      'import_id' => array('import_id')
+      'import_id' => array('import_id'),
     ),
   );
   return $schema;
 }
 
 function user_import_update_1() {
-  $ret = array(); 
+  $ret = array();
   _system_update_utf8(array('user_import', 'user_import_errors'));
   return $ret;
 }
@@ -162,32 +161,59 @@ function user_import_update_2() {
 function user_import_update_3() {
   $ret = array();
   db_drop_primary_key($ret, 'user_import');
-  db_change_field($ret, 'user_import', 'iid', 'import_id', array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE, 'disp-width' => '10'), array('primary key' => array('import_id')));
-  db_change_field($ret, 'user_import', 'first_line', 'first_line_skip', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-width' => '10'), array('primary key' => array('import_id')));
-	db_drop_index($ret, 'user_import_errors', 'import_id');
-  db_change_field($ret, 'user_import_errors', 'iid', 'import_id', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0, 'disp-width' => '10'));
-	db_add_index($ret, 'user_import_errors', 'import_id', array('import_id'));
+  db_change_field($ret, 'user_import', 'iid', 'import_id', array(
+    'type' => 'serial',
+    'unsigned' => TRUE,
+    'not null' => TRUE,
+    'disp-width' => '10',
+  ), array('primary key' => array('import_id')));
+  db_change_field($ret, 'user_import', 'first_line', 'first_line_skip', array(
+    'type' => 'int',
+    'unsigned' => TRUE,
+    'not null' => TRUE,
+    'default' => 0,
+    'disp-width' => '10',
+  ), array('primary key' => array('import_id')));
+  db_drop_index($ret, 'user_import_errors', 'import_id');
+  db_change_field($ret, 'user_import_errors', 'iid', 'import_id', array(
+    'type' => 'int',
+    'unsigned' => TRUE,
+    'not null' => TRUE,
+    'default' => 0,
+    'disp-width' => '10',
+  ));
+  db_add_index($ret, 'user_import_errors', 'import_id', array('import_id'));
   return $ret;
 }
 
 function user_import_update_4() {
   $ret = array();
-	db_drop_index($ret, 'user_import_errors', 'import_id'); 
-  db_change_field($ret, 'user_import_errors', 'error', 'errors', array('type' => 'text', 'size' => 'big', 'not null' => TRUE, 'serialize' => TRUE));
-	db_add_index($ret, 'user_import_errors', 'import_id', array('import_id'));
+  db_drop_index($ret, 'user_import_errors', 'import_id');
+  db_change_field($ret, 'user_import_errors', 'error', 'errors', array(
+    'type' => 'text',
+    'size' => 'big',
+    'not null' => TRUE,
+    'serialize' => TRUE,
+  ));
+  db_add_index($ret, 'user_import_errors', 'import_id', array('import_id'));
   return $ret;
 }
 
 function user_import_update_5() {
   $ret = array();
-	db_drop_index($ret, 'user_import_errors', 'import_id'); 
-  db_change_field($ret, 'user_import_errors', 'errors', 'errors', array('type' => 'text', 'size' => 'big', 'not null' => TRUE, 'serialize' => TRUE));
-	db_add_index($ret, 'user_import_errors', 'import_id', array('import_id'));
+  db_drop_index($ret, 'user_import_errors', 'import_id');
+  db_change_field($ret, 'user_import_errors', 'errors', 'errors', array(
+    'type' => 'text',
+    'size' => 'big',
+    'not null' => TRUE,
+    'serialize' => TRUE,
+  ));
+  db_add_index($ret, 'user_import_errors', 'import_id', array('import_id'));
   return $ret;
 }
 
 function user_import_update_6001() {
-  // Rebuild schema cache
+  // Rebuild schema cache.
   drupal_get_schema('user_import', TRUE);
   return array();
 }
@@ -200,21 +226,21 @@ function user_import_update_6002() {
   $result = db_query("SELECT * FROM {user_import}");
 
   // Update each import.
-  while ($import = db_fetch_array($result)) { 
-		$options = unserialize($import['options']);
-		$options['first_line_skip'] = $import['first_line_skip'];
-		$options['contact'] = $import['contact'];
-		$options['username_space'] = $import['username_space'];
-		$options['send_email'] = $import['send_email']; 
-		//Avoid using update_sql() as it has issues with serialized data.
+  while ($import = db_fetch_array($result)) {
+    $options = unserialize($import['options']);
+    $options['first_line_skip'] = $import['first_line_skip'];
+    $options['contact'] = $import['contact'];
+    $options['username_space'] = $import['username_space'];
+    $options['send_email'] = $import['send_email'];
+    // Avoid using update_sql() as it has issues with serialized data.
     db_query("UPDATE {user_import} SET options = '%s' WHERE import_id = %d", serialize($options), $import['import_id']);
-	}
-	
-	$ret[] = update_sql('ALTER TABLE {user_import} DROP COLUMN first_line_skip');
-	$ret[] = update_sql('ALTER TABLE {user_import} DROP COLUMN contact');
-	$ret[] = update_sql('ALTER TABLE {user_import} DROP COLUMN username_space');
-	$ret[] = update_sql('ALTER TABLE {user_import} DROP COLUMN send_email');
-	
+  }
+
+  $ret[] = update_sql('ALTER TABLE {user_import} DROP COLUMN first_line_skip');
+  $ret[] = update_sql('ALTER TABLE {user_import} DROP COLUMN contact');
+  $ret[] = update_sql('ALTER TABLE {user_import} DROP COLUMN username_space');
+  $ret[] = update_sql('ALTER TABLE {user_import} DROP COLUMN send_email');
+
   return $ret;
 }
 
@@ -223,13 +249,18 @@ function user_import_update_6002() {
  */
 function user_import_update_6003() {
   $ret = array();
-  db_change_field($ret, 'user_import', 'roles', 'roles', array('type' => 'text', 'size' => 'big', 'not null' => TRUE, 'serialize' => TRUE)); 
+  db_change_field($ret, 'user_import', 'roles', 'roles', array(
+    'type' => 'text',
+    'size' => 'big',
+    'not null' => TRUE,
+    'serialize' => TRUE,
+  ));
   return $ret;
 }
 
 /**
-* Implementation of hook_uninstall().
-*/
+ * Implements hook_uninstall().
+ */
 function user_import_uninstall() {
   drupal_uninstall_schema('user_import');
   variable_del('user_import_settings');
@@ -238,4 +269,3 @@ function user_import_uninstall() {
   variable_del('user_export_checked_usernames');
   variable_del('user_import_profile_date_format');
 }
-
diff --git a/user_import.module b/user_import.module
index 656986b..2525061 100644
--- a/user_import.module
+++ b/user_import.module
@@ -1,21 +1,20 @@
 <?php
-
 /**
  * @file
  * Import or update users with data from a comma separated file (csv).
  */
 
-// Update options for existing users
-define ('UPDATE_NONE', 0);
-define ('UPDATE_REPLACE', 1);
-define ('UPDATE_ADD', 2);
+// Update options for existing users.
+define('UPDATE_NONE', 0);
+define('UPDATE_REPLACE', 1);
+define('UPDATE_ADD', 2);
 
 /**
- * - - - - - - - -  HOOKS - - - - - - - - 
+ * - - - - - - - -  HOOKS - - - - - - - -
  */
 
 /**
- * Implementation of hook_theme().
+ * Implements hook_theme().
  */
 function user_import_theme() {
   return array(
@@ -30,12 +29,12 @@ function user_import_theme() {
     ),
     'user_import_username_errors' => array(
       'arguments' => array('errors' => NULL),
-    ), 
+    ),
   );
 }
 
 /**
- * Implementation of hook_help().
+ * Implements hook_help().
  */
 function user_import_help($path, $arg) {
   switch ($path) {
@@ -45,31 +44,31 @@ function user_import_help($path, $arg) {
 }
 
 /**
- * Implementation of hook_perm().
+ * Implements hook_perm().
  */
 function user_import_perm() {
   return array('import users');
 }
 
 /**
- * Implementation of hook_menu().
+ * Implements hook_menu().
  */
 function user_import_menu() {
   $items['admin/user/user_import'] = array(
-      'title' => 'User Imports',
-      'description' => 'Import or update users from a comma separated file (csv).',
-      'page callback' => 'user_import_list',
-      'access arguments' => array('import users'),
-      'file' => 'user_import.admin.inc',
-      );
-  $items['admin/user/user_import/list'] = array( 
-      'title' => 'List Imports', 
-      'access arguments' => array('import users'),
-      'weight' => -10,
-      'type' => MENU_DEFAULT_LOCAL_TASK,
-      'file' => 'user_import.admin.inc',
-      );
-  $items['admin/user/user_import/add'] = array( 
+    'title' => 'User Imports',
+    'description' => 'Import or update users from a comma separated file (csv).',
+    'page callback' => 'user_import_list',
+    'access arguments' => array('import users'),
+    'file' => 'user_import.admin.inc',
+  );
+  $items['admin/user/user_import/list'] = array(
+    'title' => 'List Imports',
+    'access arguments' => array('import users'),
+    'weight' => -10,
+    'type' => MENU_DEFAULT_LOCAL_TASK,
+    'file' => 'user_import.admin.inc',
+  );
+  $items['admin/user/user_import/add'] = array(
     'title' => 'Import',
     'page callback' => 'user_import_preferences',
     'access arguments' => array('import users'),
@@ -77,14 +76,14 @@ function user_import_menu() {
     'type' => MENU_LOCAL_TASK,
     'file' => 'user_import.admin.inc',
   );
-  $items['admin/user/user_import/continue'] = array( 
+  $items['admin/user/user_import/continue'] = array(
     'title' => 'Continue',
     'page callback' => 'user_import_continue',
     'access arguments' => array('import users'),
     'type' => MENU_CALLBACK,
     'file' => 'user_import.admin.inc',
   );
-  $items['admin/user/user_import/import'] = array( 
+  $items['admin/user/user_import/import'] = array(
     'title' => 'Import',
     'page callback' => 'user_import_import',
     'access arguments' => array('import users'),
@@ -106,7 +105,7 @@ function user_import_menu() {
     'type' => MENU_LOCAL_TASK,
     'file' => 'user_import.admin.inc',
   );
-  $items['user_import/delete'] = array( 
+  $items['user_import/delete'] = array(
     'title' => 'Remove Info',
     'page callback' => 'user_import_limited_delete',
     'type' => MENU_CALLBACK,
@@ -117,139 +116,157 @@ function user_import_menu() {
     'page callback' => 'user_import_limited_errors',
     'type' => MENU_CALLBACK,
     'access arguments' => array('limited user import'),
-  ); 
+  );
 
   return $items;
 }
 
 /**
- * Implementation of hook_cron().
+ * Implements hook_cron().
  */
 function user_import_cron() {
   module_load_include('inc', 'user_import', 'user_import.import');
-	$imports = _user_import_settings_select();
+  $imports = _user_import_settings_select();
 
-	if (!$imports) return;
+  if (!$imports) {
+    return;
+  }
 
-	foreach ($imports as $import) {
-		if ($import['setting'] == 'test' || $import['setting'] == 'import') { 
-			_user_import_process($import);
-		}
-	}
-   
-	return;
+  foreach ($imports as $import) {
+    if ($import['setting'] == 'test' || $import['setting'] == 'import') {
+      _user_import_process($import);
+    }
+  }
+
+  return;
 }
 
-// - - - - - - - -  FORMS - - - - - - - - 
-
+// - - - - - - - -  FORMS - - - - - - - -
 /**
- * Saves options on content type configuration form 
+ * Saves options on content type configuration form.
  * @todo check if this is cruft
  * @todo check $form['type']
  */
 function user_import_content_type_submit($form, &$form_state) {
-  // user import template for Organic Groups content type
+  // User import template for Organic Groups content type.
   $templates = variable_get('user_import_og_template', array());
   $templates[$form['type']] = $form_state['values']['user_import_og'];
   variable_set('user_import_og_template', $templates);
 }
 
-// - - - - - - - -  PAGES - - - - - - - - 
-
+// - - - - - - - -  PAGES - - - - - - - -
 function user_import_limited_errors($import_id = NULL, $template_id = NULL) {
 
-  if (empty($import_id) || !is_numeric($import_id)) drupal_goto('user_import/' . $template_id);
- 
+  if (empty($import_id) || !is_numeric($import_id)) {
+    drupal_goto('user_import/' . $template_id);
+  }
+
   $pager_id = 1;
   $max = 25;
   $import = _user_import_settings_select($import_id);
-  
+
   $total = db_result(db_query("SELECT count(data) FROM {user_import_errors} WHERE import_id = %d", $import['import_id']));
-  
-  if (empty($total))  {
-  
+
+  if (empty($total)) {
     $output .= theme('There were no import errors');
-  
-  } else {
-  
+  }
+  else {
+
     $results = pager_query("SELECT * FROM {user_import_errors} WHERE import_id = %d", $max, $pager_id, NULL, array($import['import_id']));
-    
+
     while ($line = db_fetch_array($results)) {
 
       $line['data'] = unserialize($line['data']);
       $line['errors'] = unserialize($line['errors']);
       $file_lines[] = $line;
     }
- 
+
     $output .= theme('user_import_errors_display', $import, $file_lines, $total);
-    $output .= theme('pager', NULL, $max, $pager_id); 
+    $output .= theme('pager', NULL, $max, $pager_id);
   }
-  
+
   $output .= l(t('Return'), "user_import/$template_id/$import_id");
- 
+
   return $output;
 }
 
-function user_import_limited_delete($import_id = NULL, $template_id = NULL) { 
+function user_import_limited_delete($import_id = NULL, $template_id = NULL) {
   user_import_delete($import_id, "user_import/$template_id");
 }
 
-// - - - - - - - -  THEMES - - - - - - - - 
-
+// - - - - - - - -  THEMES - - - - - - - -
 function theme_user_import_list() {
   $output = '';
   $imports = _user_import_settings_select();
-  
-  if (!$imports) return ' ';
+
+  if (!$imports) {
+    return ' ';
+  }
 
   foreach ($imports as $import) {
 
-      // header labels
-      $import_label = ($import['setting'] == 'tested' || $import['setting'] == 'test') ? t('importable') : t('imported');
-      $header = array(t('file'), t('started'), t('processed'), $import_label, t('errors'), t('status'));
-                  
-      // info row
-      $errors = db_result(db_query("SELECT COUNT(import_id) FROM {user_import_errors} WHERE import_id = %d", $import['import_id']));         
-      $errors_link = ($errors == 0) ? '0': l($errors, 'admin/user/user_import/errors/' . $import['import_id']);           
-      
-      $rows[0] = array(
-          check_plain($import['oldfilename']),
-          format_date($import['started'], 'small'),
-          array("data" => $import['processed'], "align" => 'center'),
-          array("data" => $import['valid'], "align" => 'center'),
-          array("data" => $errors_link, "align" => 'center'),
-          $import['setting'],
-      );
-      
-      $output .= theme('table', $header, $rows);
-      
-      // action buttons
-      $settings_link = l(t('Settings'), 'admin/user/user_import/add/' . $import['import_id']);
-      $delete_link = l(t('Delete'), 'admin/user/user_import/delete/' . $import['import_id']);
-      $continue_link = l(t('Continue Processing'), 'admin/user/user_import/continue/' . $import['import_id']);
-      $import_link = l(t('Import'), 'admin/user/user_import/import/' . $import['import_id']);
-      
-      $output .= $settings_link  . ' | ';   
-      $output .= $delete_link;   
-      if ($import['setting'] == 'tested' || $import['setting'] == 'test') $output .= ' | ' . $import_link;
-      if ($import['setting'] == 'test' || $import['setting']  == 'import') $output .= ' | ' . $continue_link;
-  } 
-  
+    // Header labels.
+    $import_label = ($import['setting'] == 'tested' || $import['setting'] == 'test') ? t('importable') : t('imported');
+    $header = array(
+      t('file'),
+      t('started'),
+      t('processed'),
+      $import_label,
+      t('errors'),
+      t('status'),
+    );
+
+    // Info row.
+    $errors = db_result(db_query("SELECT COUNT(import_id) FROM {user_import_errors} WHERE import_id = %d", $import['import_id']));
+    $errors_link = ($errors == 0) ? '0': l($errors, 'admin/user/user_import/errors/' . $import['import_id']);
+
+    $rows[0] = array(
+      check_plain($import['oldfilename']),
+      format_date($import['started'], 'small'),
+      array("data" => $import['processed'], "align" => 'center'),
+      array("data" => $import['valid'], "align" => 'center'),
+      array("data" => $errors_link, "align" => 'center'),
+      $import['setting'],
+    );
+
+    $output .= theme('table', $header, $rows);
+
+    // Action buttons.
+    $settings_link = l(t('Settings'), 'admin/user/user_import/add/' . $import['import_id']);
+    $delete_link = l(t('Delete'), 'admin/user/user_import/delete/' . $import['import_id']);
+    $continue_link = l(t('Continue Processing'), 'admin/user/user_import/continue/' . $import['import_id']);
+    $import_link = l(t('Import'), 'admin/user/user_import/import/' . $import['import_id']);
+
+    $output .= $settings_link  . ' | ';
+    $output .= $delete_link;
+    if ($import['setting'] == 'tested' || $import['setting'] == 'test') {
+      $output .= ' | ' . $import_link;
+    }
+    if ($import['setting'] == 'test' || $import['setting'] == 'import') {
+      $output .= ' | ' . $continue_link;
+    }
+  }
+
   return $output;
 }
 
 function theme_user_import_edit($form) {
- 
-  $header = array(t('CSV column'), t('Drupal fields'), t('Username'), t('Abbreviate'));
+
+  $header = array(
+    t('CSV column'),
+    t('Drupal fields'),
+    t('Username'),
+    t('Abbreviate'),
+  );
 
   foreach (element_children($form['field_match']) as $key) {
 
-	  $rows[] = array(
-	      drupal_render($form['field_match'][$key]['csv']),
-	      drupal_render($form['field_match'][$key]['field_match']),
-	      drupal_render($form['field_match'][$key]['username']),
-	      drupal_render($form['field_match'][$key]['abbreviate']),
-	  );
+    $rows[] = array(
+      drupal_render($form['field_match'][$key]['csv']),
+      drupal_render($form['field_match'][$key]['field_match']),
+      drupal_render($form['field_match'][$key]['username']),
+      drupal_render($form['field_match'][$key]['abbreviate']),
+    );
   }
 
   $form['field_match']['#value'] = theme('table', $header, $rows);
@@ -262,183 +279,202 @@ function theme_user_import_edit($form) {
 }
 
 function theme_user_import_errors_display($settings, $data, $total) {
-    $output = '';
-    $error_count = 0;
-    $field_match = _user_import_unconcatenate_field_match($settings['field_match']);
-    $header[0] = t('Email Address');
-
-    foreach ($data as $data_row) {
-
-        $row = NULL;
-        
-        foreach ($data_row['data'] as $type => $fields) {
-   
-          if (!empty($fields)) {
-          
-            foreach ($fields as $field_id => $field_data) {
-  
-              foreach ($field_match as $column_info) {
-              
-                if ($column_info['type'] ==  $type && $column_info['field_id'] == $field_id) {
-                  
-                  if (!empty($column_info['username'])) { 
-                    $header[$column_info['username']] = t('Name %sort', array('%sort' => $column_info['username']));
-                    $row[$column_info['username']] = array("data" => $field_data[0], "align" => "left");
-                  }
-                  
-                  if ($column_info['field_id'] == 'email') { 
-                    $row[0] = array("data" => $field_data[0], "align" => "left");
-                  }
-                }
+  $output = '';
+  $error_count = 0;
+  $field_match = _user_import_unconcatenate_field_match($settings['field_match']);
+  $header[0] = t('Email Address');
+
+  foreach ($data as $data_row) {
+
+    $row = NULL;
+
+    foreach ($data_row['data'] as $type => $fields) {
+
+      if (!empty($fields)) {
+
+        foreach ($fields as $field_id => $field_data) {
+
+          foreach ($field_match as $column_info) {
+
+            if ($column_info['type'] == $type && $column_info['field_id'] == $field_id) {
+
+              if (!empty($column_info['username'])) {
+                $header[$column_info['username']] = t('Name %sort', array('%sort' => $column_info['username']));
+                $row[$column_info['username']] = array("data" => $field_data[0], "align" => "left");
               }
-            
-            } 
-          }  
+
+              if ($column_info['field_id'] == 'email') {
+                $row[0] = array("data" => $field_data[0], "align" => "left");
+              }
+            }
+          }
+
         }
-  
-        ksort($row);
-        $row[] = implode('<br />', $data_row['errors']);
-        $rows[] = $row;
+      }
     }
-    
-    $output .= '<p>' . t('<strong>CSV File:</strong> %file', array('%file' => $settings['oldfilename'])) . '<br />';
-    $output .= t('<strong>Errors:</strong> !total', array('!total' => $total)) . '</p>';
 
-    $header['errors'] = t('Errors');
-    $output .= theme('table', $header, $rows);    
-    return $output;
+    ksort($row);
+    $row[] = implode('<br />', $data_row['errors']);
+    $rows[] = $row;
+  }
+
+  $output .= '<p>' . t('<strong>CSV File:</strong> %file', array('%file' => $settings['oldfilename'])) . '<br />';
+  $output .= t('<strong>Errors:</strong> !total', array('!total' => $total)) . '</p>';
+
+  $header['errors'] = t('Errors');
+  $output .= theme('table', $header, $rows);
+  return $output;
 }
 
 function theme_user_import_username_errors($errors) {
-    
-    if (empty($errors)) {
-        $output = '<p><strong>' . t('All usernames are OK.') . '</strong></p>';
-    } else {
-        $header = array(t('User ID'), t('Email'), t('Username'), t('Error'));
-        $output = theme('table', $header, $errors);
-    }
-    
-    return $output;
+
+  if (empty($errors)) {
+    $output = '<p><strong>' . t('All usernames are OK.') . '</strong></p>';
+  }
+  else {
+    $header = array(t('User ID'), t('Email'), t('Username'), t('Error'));
+    $output = theme('table', $header, $errors);
+  }
+
+  return $output;
 }
 
-// - - - - - - - -  MISC - - - - - - - - 
-
+// - - - - - - - -  MISC - - - - - - - -
 function _user_import_settings_save($settings) {
   // Database field defaults.
-  $database_fields = array('import_id' => NULL, 
-													 'name' => '', 
-													 'filename' => '', 
-													 'oldfilename' => '', 
-													 'filepath' => '', 
-													 'started' => 0, 
-													 'pointer' => 0, 
-													 'processed' => 0, 
-													 'valid' => 0, 
-													 'field_match' => array(), 
-													 'roles' => '', 
-													 'options' => array(), 
-													 'setting' => '',
-													);												
+  $database_fields = array(
+    'import_id' => NULL,
+    'name' => '',
+    'filename' => '',
+    'oldfilename' => '',
+    'filepath' => '',
+    'started' => 0,
+    'pointer' => 0,
+    'processed' => 0,
+    'valid' => 0,
+    'field_match' => array(),
+    'roles' => '',
+    'options' => array(),
+    'setting' => '',
+  );
 
- 	// Form elements we never want to save in the options column.
-  $form_variables = array('form_id', 'form_token', 'form_build_id', 'cancel', 'import', 'submit', 'op', 0, 'return_path');
+  // Form elements we never want to save in the options column.
+  $form_variables = array(
+    'form_id',
+    'form_token',
+    'form_build_id',
+    'cancel',
+    'import',
+    'submit',
+    'op',
+    0,
+    'return_path',
+  );
   $form_variables = array_flip($form_variables);
 
   // Remove settings we don't need in the options column.
-	$options = array_diff_key($settings, $database_fields);
+  $options = array_diff_key($settings, $database_fields);
   $options = array_diff_key($options, $form_variables);
 
   // Set defaults for options.
-	foreach ($options as $key => $value) {
-		$settings['options'][$key] = isset($settings[$key]) ? $settings[$key] : '';
-	}
+  foreach ($options as $key => $value) {
+    $settings['options'][$key] = isset($settings[$key]) ? $settings[$key] : '';
+  }
 
-  // Set defaults for fields. 
-	foreach ($database_fields as $key => $value) {
-		$settings[$key] = isset($settings[$key]) ? $settings[$key] : $value;
-	}
-   
-   // Update settings for existing import
-   if (isset($settings['import_id'])) {
-   
-       db_query("UPDATE {user_import} 
-           SET name = '%s', filename = '%s', oldfilename = '%s', filepath = '%s', pointer = %d, processed = %d, valid= %d, field_match = '%s', roles = '%s', options = '%s', setting = '%s' 
-           WHERE import_id = %d
-           ", trim($settings['name']), $settings['filename'], $settings['oldfilename'], $settings['filepath'], $settings['pointer'], $settings['processed'], $settings['valid'], serialize($settings['field_match']), serialize($settings['roles']), serialize($settings['options']), $settings['setting'], $settings['import_id']);
-       
-   // Save settings for new import
-   } 
-   else {
+  // Set defaults for fields.
+  foreach ($database_fields as $key => $value) {
+    $settings[$key] = isset($settings[$key]) ? $settings[$key] : $value;
+  }
 
-       db_query("INSERT INTO {user_import} 
-           (name, filename, oldfilename, filepath, started, pointer, processed, valid, field_match, roles, options, setting) 
+  // Update settings for existing import.
+  if (isset($settings['import_id'])) {
+
+    db_query("UPDATE {user_import}
+          SET name = '%s', filename = '%s', oldfilename = '%s', filepath = '%s', pointer = %d, processed = %d, valid= %d, field_match = '%s', roles = '%s', options = '%s', setting = '%s'
+          WHERE import_id = %d
+          ", trim($settings['name']), $settings['filename'], $settings['oldfilename'], $settings['filepath'], $settings['pointer'], $settings['processed'], $settings['valid'], serialize($settings['field_match']), serialize($settings['roles']), serialize($settings['options']), $settings['setting'], $settings['import_id']);
+
+    // Save settings for new import.
+  }
+  else {
+
+    db_query("INSERT INTO {user_import}
+           (name, filename, oldfilename, filepath, started, pointer, processed, valid, field_match, roles, options, setting)
            VALUES ('%s', '%s', '%s', '%s', %d, %d, %d, %d, '%s', '%s', '%s', '%s')
            ", trim($settings['name']), $settings['filename'], $settings['oldfilename'], $settings['filepath'], time(), $settings['pointer'], $settings['processed'], $settings['valid'], serialize($settings['field_match']), serialize($settings['roles']), serialize($settings['options']), $settings['setting']);
 
-       switch ($GLOBALS['db_type']) {
-         case 'mysql':
-         case 'mysqli':
-           $settings['import_id'] = db_result(db_query("SELECT LAST_INSERT_ID()"));
-           break;
-         case 'pgsql':
-           $settings['import_id'] = db_result(db_query("SELECT currval('{user_import_import_id_seq}')"));
-           break;
-       }
-   }
-   
-   return $settings;
+    switch ($GLOBALS['db_type']) {
+      case 'mysql':
+      case 'mysqli':
+        $settings['import_id'] = db_result(db_query("SELECT LAST_INSERT_ID()"));
+        break;
+
+      case 'pgsql':
+        $settings['import_id'] = db_result(db_query("SELECT currval('{user_import_import_id_seq}')"));
+        break;
+
+    }
+  }
+
+  return $settings;
 }
 
 /**
- *  Return either a single import setting, or all template, or all non-template settings.
+ * Return single import setting, or all template, or all non-template settings.
  */
 function _user_import_settings_select($import_id = NULL, $template = FALSE) {
 
   $import = array();
 
-  if (!empty($import_id) && !is_numeric($import_id)) return;
+  if (!empty($import_id) && !is_numeric($import_id)) {
+    return;
+  }
 
   if (!empty($import_id)) {
-	  $sql = 'SELECT * FROM {user_import} WHERE import_id = %d';
-	  if ($template) $sql .=  " AND setting = 'template'";
-	  $import = db_fetch_array(db_query_range($sql, $import_id, 0, 1));
+    $sql = 'SELECT * FROM {user_import} WHERE import_id = %d';
+    if ($template) {
+      $sql .= " AND setting = 'template'";
+    }
+    $import = db_fetch_array(db_query_range($sql, $import_id, 0, 1));
 
-	  if (empty($import)) return FALSE;
+    if (empty($import)) {
+      return FALSE;
+    }
 
-	  $import['field_match'] = unserialize($import['field_match']);
-	  $import['roles'] = unserialize($import['roles']);
-	  $import['options'] = unserialize($import['options']);
-	
-		foreach ($import['options'] as $key => $value) {
-			$import[$key] = $value;
-		}
-  } 
+    $import['field_match'] = unserialize($import['field_match']);
+    $import['roles'] = unserialize($import['roles']);
+    $import['options'] = unserialize($import['options']);
+
+    foreach ($import['options'] as $key => $value) {
+      $import[$key] = $value;
+    }
+  }
   else {
-    
-      $query = ($template) ? "SELECT * FROM {user_import} WHERE setting = 'template'" : "SELECT * FROM {user_import} WHERE setting != 'template' ORDER BY started DESC";
-      $results = db_query($query);
 
-      while ($row = db_fetch_array($results)) {
-          $row['field_match'] = unserialize($row['field_match']);
-          $row['roles'] = unserialize($row['roles']);
-          $row['options'] = unserialize($row['options']);
+    $query = ($template) ? "SELECT * FROM {user_import} WHERE setting = 'template'" : "SELECT * FROM {user_import} WHERE setting != 'template' ORDER BY started DESC";
+    $results = db_query($query);
 
-					foreach ($row['options'] as $key => $value) {
-						$row[$key] = $value;
-					}
+    while ($row = db_fetch_array($results)) {
+      $row['field_match'] = unserialize($row['field_match']);
+      $row['roles'] = unserialize($row['roles']);
+      $row['options'] = unserialize($row['options']);
 
-          $import[] = $row;
+      foreach ($row['options'] as $key => $value) {
+        $row[$key] = $value;
       }
+
+      $import[] = $row;
+    }
   }
 
-  return $import;      
+  return $import;
 }
 
 function _user_import_settings_deletion($import_id) {
 
-    db_query("DELETE FROM {user_import} WHERE import_id = %d", $import_id);
-    db_query("DELETE FROM {user_import_errors} WHERE import_id = %d", $import_id);
-    return;
+  db_query("DELETE FROM {user_import} WHERE import_id = %d", $import_id);
+  db_query("DELETE FROM {user_import_errors} WHERE import_id = %d", $import_id);
+  return;
 }
 
 // Used by user_import_og.module
@@ -447,14 +483,14 @@ function user_import_profile_load($user) {
   $result = db_query('SELECT f.name, f.type, f.fid, v.value FROM {profile_fields} f INNER JOIN {profile_values} v ON f.fid = v.fid WHERE uid = %d', $user->uid);
 
   while ($field = db_fetch_object($result)) {
-  
+
     if (empty($profile[$field->fid])) {
-      
+
       $profile[$field->fid] = _profile_field_serialize($field->type) ? unserialize($field->value) : $field->value;
     }
-    
+
   }
-  
+
   return $profile;
 }
 
@@ -463,14 +499,14 @@ function _user_import_unconcatenate_field_match($settings) {
   $settings_updated = array();
 
   foreach ($settings as $column_id => $values) {
-    
+
     if (!empty($values['field_match']) || !empty($values['username'])) {
       // If we have a username but no field_match, set a special type.
       // This allows us to skip saving the field but still use it in
       // concatenating a username value.
       if (empty($values['field_match'])) {
         $values['type'] = 'username_part';
-        $values['field_id'] = 'username_part_'. $column_id;
+        $values['field_id'] = 'username_part_' . $column_id;
       }
       else {
         $key_parts = explode('-', $values['field_match']);
@@ -481,7 +517,7 @@ function _user_import_unconcatenate_field_match($settings) {
       $settings_updated[$column_id] = $values;
     }
   }
-  
+
   return $settings_updated;
 }
 
@@ -498,25 +534,20 @@ function user_import_load_supported() {
     foreach ($files as $module_name => $file) {
 
       if (module_exists($module_name)) {
-        include_once($file->filename);
+        include_once $file->filename;
       }
     }
 
     $loaded = TRUE;
   }
-}   
+}
 
 /**
-* Implementation of hook_simpletest().
-*/
+ * Implements hook_simpletest().
+ */
 function user_import_simpletest() {
   $module_name = 'user_import';
-  $dir = drupal_get_path('module', $module_name). '/tests';
+  $dir = drupal_get_path('module', $module_name) . '/tests';
   $tests = file_scan_directory($dir, '\.test$');
   return array_keys($tests);
 }
-
-
-
-
-
diff --git a/user_import.test b/user_import.test
index d2aefe8..07ce62d 100644
--- a/user_import.test
+++ b/user_import.test
@@ -1,128 +1,132 @@
 <?php
-// $Id$
-//$this->pass(var_export($modules, TRUE));
-// debug($this->admin_user);
-//file_put_contents('output.html', $this->drupalGetContent());  
-
 /**
+ * @file
  * User Import module base test class.
  */
+
 class UserImportWebTestCase extends DrupalWebTestCase {
-	protected $admin_user;
-	protected $user_importer;
+  protected $admin_user;
+  protected $user_importer;
 
   /**
-   *  Select CSV file (the included example file) 
-  */ 
+   * Select CSV file (the included example file).
+   */
   function settingsFileSelect() {
     $edit = array('file_ftp' => 1);
     $this->drupalPost('admin/user/user_import/add', $edit, 'Next');
 
-    /* Check file was selected */
+    // Check file was selected.
     $this->assertText(t('Use Different CSV File'), '[assert] File was selected');
   }
 
   function settingsEmailMatch(&$edit) {
     $edit['field_match[5][field_match]'] = 'user-email';
   }
-  
+
   function settingsIgnoreFirstLine(&$edit) {
     $edit['first_line_skip'] = 1;
   }
-  
+
   function checkAccountsExist($list_failures = FALSE) {
-		$failures_list = ''; 
+    $failures_list = '';
     $users_email = $this->usersList();
     $failed = array();
-    
+
     foreach ($users_email as $mail) {
       $user = user_load(array('mail' => $mail));
-      if (empty($user)) $failed[] = $mail; 
+      if (empty($user)) {
+        $failed[] = $mail;
+      }
     }
-    
+
     if (!empty($failed) && $list_failures) {
       $failures_list = t('. Failed accounts: %failures', array('%failures' => implode(', ', $failed)));
     }
-    
+
     $this->assertTrue(empty($failed), t('Accounts created for users imported') . $failures_list);
-    
+
   }
-  
+
   /**
-   *  List of users (email addresses) being imported
-   *  To Do - Generate this dynamically, bearing in mind it could be used for stress testing
+   * List of users (email addresses) being imported.
+   *
+   * To Do - Generate this dynamically, bearing in mind it could be used
+   * for stress testing.
    */
   function usersList() {
     return array(
-        'john@example.com', 
-        'mandy@example.com', 
-        'charles@example.com', 
-        'sarah@example.com', 
-        'sarah_smith@example.com', 
-        'helen@example.com', 
-        'claire@example.com', 
-        'victoria@example.com', 
-        'james@example.com',
-        'anna@example.com',
-        'tino@example.com',
-        'sofia@example.com',
-        'steve@example.com',
-        'lucy@example.com',
-        'angie@example.com',
-        'carmen@example.com',
-        'paul@example.com',
-        'jason@example.com',
-        'mike@example.com',
-        'mary@example.com',
-        'simon@example.com',
-        'kieran@example.com',
-        'arthur@example.com',
-        'gwen@example.com',
-        'chester@example.com',
-        'dorothy@example.com',
-        'cameron@example.com',
-        'trisha@example.com',
-        'david@example.com',
-        'peter@example.com',
-        'saul@example.com',
-        'noel@example.com',
-        'matt@example.com',
-        'aston@example.com',
-        'mille@example.com',
-        'ernest@example.com',
-      );
+      'john@example.com',
+      'mandy@example.com',
+      'charles@example.com',
+      'sarah@example.com',
+      'sarah_smith@example.com',
+      'helen@example.com',
+      'claire@example.com',
+      'victoria@example.com',
+      'james@example.com',
+      'anna@example.com',
+      'tino@example.com',
+      'sofia@example.com',
+      'steve@example.com',
+      'lucy@example.com',
+      'angie@example.com',
+      'carmen@example.com',
+      'paul@example.com',
+      'jason@example.com',
+      'mike@example.com',
+      'mary@example.com',
+      'simon@example.com',
+      'kieran@example.com',
+      'arthur@example.com',
+      'gwen@example.com',
+      'chester@example.com',
+      'dorothy@example.com',
+      'cameron@example.com',
+      'trisha@example.com',
+      'david@example.com',
+      'peter@example.com',
+      'saul@example.com',
+      'noel@example.com',
+      'matt@example.com',
+      'aston@example.com',
+      'mille@example.com',
+      'ernest@example.com',
+    );
   }
 
   /**
-   * Store import ID
-   * - set on import settings page, retrieve on later tasks
+   * Store import ID.
+   *
+   * Set on import settings page, retrieve on later tasks.
    */
   function importID($url = NULL) {
     static $import_id = 0;
-    
+
     if (empty($import_id) && !empty($url)) {
       $args = explode('/', $url);
       $import_id = $args[7];
     }
-    
+
     return $import_id;
   }
 
   /**
    * SimpleTest core method: code run after each and every test method.
-  */
+   */
   function tearDown() {
-    // delete accounts of users imported
+    // Delete accounts of users imported.
     $users_email = $this->usersList();
 
     foreach ($users_email as $mail) {
       $account = user_load(array('mail' => $mail));
-      if (!empty($account)) user_delete(array(), $account->uid); 
+      if (!empty($account)) {
+        user_delete(array(), $account->uid);
+      }
     }
-    
-    // delete the import
-    $import_id = $this->importID();   
-    $this->assertTrue(!empty($import_id), t('Import ID: !id', array('!id' => $import_id))); 
+
+    // Delete the import.
+    $import_id = $this->importID();
+    $this->assertTrue(!empty($import_id), t('Import ID: !id', array('!id' => $import_id)));
     _user_import_settings_deletion($import_id);
 
     // Always call the tearDown() function from the parent class.
@@ -146,31 +150,37 @@ class UserImportBasicsTestCase extends UserImportWebTestCase {
   }
 
   function setUp() {
-  			parent::setUp('user_import');
-  	    $this->admin_user = $this->drupalCreateUser(array('administer users', 'access administration pages', 'administer site configuration'));
-  	    $this->user_importer = $this->drupalCreateUser(array('import users'));
-  } 
-	
+    parent::setUp('user_import');
+    $this->admin_user = $this->drupalCreateUser(array(
+      'administer users',
+      'access administration pages',
+      'administer site configuration',
+    ));
+    $this->user_importer = $this->drupalCreateUser(array('import users'));
+  }
+
   /**
-   *  User with right permissions creates import (with new settings)
-   *  - test core functions
+   * User with right permissions creates import (with new settings).
+   *
+   * Test core functions.
    */
   function testCreateImport() {
 
-    // Prepare a user to do testing
+    // Prepare a user to do testing.
     $this->drupalLogin($this->user_importer);
 
-    // Select CSV file (the included example file)
+    // Select CSV file (the included example file).
     $this->settingsFileSelect();
-    
-    // import settings 
-    $this->importID($this->getUrl()); // store import ID for later
+
+    // Import settings.
+    $this->importID($this->getUrl());
+    // Store import ID for later.
     $setting_edit = array();
     $this->settingsEmailMatch($settings);
     $this->settingsIgnoreFirstLine($settings);
     $this->drupalPost($this->getUrl(), $settings, 'Import');
-    
-    // check if users have been imported
+
+    // Check if users have been imported.
     $this->checkAccountsExist(TRUE);
   }
 
@@ -180,8 +190,8 @@ class UserImportBasicsTestCase extends UserImportWebTestCase {
 /**
  *  Test import of user data into Profile module
  */
-class UserImportNodeprofileTestCase extends UserImportWebTestCase {  
-	
+class UserImportNodeprofileTestCase extends UserImportWebTestCase {
+
   public static function getInfo() {
     return array(
       'name' => 'Import Users (Nodeprofile)',
@@ -191,149 +201,234 @@ class UserImportNodeprofileTestCase extends UserImportWebTestCase {
   }
 
   function setUp() {
-			parent::setUp('content', 'number', 'optionwidgets', 'text', 'link', 'date_api', 'date', 'node_import', 'content_profile', 'user_import');
-	    $this->admin_user = $this->drupalCreateUser(array('administer users', 'administer permissions', 'access administration pages', 'administer site configuration', 'administer content types', 'administer taxonomy'));
-	    $this->user_importer = $this->drupalCreateUser(array('import users'));
+    parent::setUp('content', 'number', 'optionwidgets', 'text', 'link', 'date_api', 'date', 'node_import', 'content_profile', 'user_import');
+    $this->admin_user = $this->drupalCreateUser(array(
+      'administer users',
+      'administer permissions',
+      'access administration pages',
+      'administer site configuration',
+      'administer content types',
+      'administer taxonomy',
+    ));
+    $this->user_importer = $this->drupalCreateUser(array('import users'));
   }
 
   /**
-   *  User with right permissions creates import (with new settings)
-   *  - test import of user data into Nodeprofile module 
+   * User with right permissions creates import (with new settings).
+   *
+   * Test import of user data into Nodeprofile module.
    */
   function testCreateImport() {
     $this->drupalLogin($this->admin_user);
-		// $this->drupalGet('admin/build/modules');
-		// file_put_contents('output.html', $this->drupalGetContent()); 
-		
+    // $this->drupalGet('admin/build/modules');
+    // file_put_contents('output.html', $this->drupalGetContent());
     $this->nodeprofileConfiguration();
-    
-    // Prepare a user to do testing 
-    $this->drupalGet('logout'); // log out first
-    $this->drupalLogin($this->user_importer);     
-  
-    // Select CSV file (the included example file)
+
+    // Prepare a user to do testing.
+    // Log out first.
+    $this->drupalGet('logout');
+    $this->drupalLogin($this->user_importer);
+
+    // Select CSV file (the included example file).
     $this->settingsFileSelect();
-    
-    // import settings 
-    $this->importID($this->getUrl()); // store import ID for later
+
+    // Import settings.
+    // Store import ID for later.
+    $this->importID($this->getUrl());
     $settings = array();
     $this->settingsEmailMatch($settings);
     $this->settingsNodeprofileMatch($settings);
     $this->settingsIgnoreFirstLine($settings);
     $this->drupalPost($this->getUrl(), $settings, 'Import');
 
-    // check if users have been imported
+    // Check if users have been imported.
     $this->checkNodeprofileExist();
 
   }
 
   /**
-   *  Configure modules
+   * Configure modules.
    */
   function nodeprofileConfiguration() {
-    
-    // create Identity content type
-    $edit = array('name' => 'Identity', 'type' => 'identity', 'title_label' => 'Title', 'body_label' => '', 'node_options[promote]' => 0, 'content_profile_use' => 1); 
+
+    // Create Identity content type.
+    $edit = array(
+      'name' => 'Identity',
+      'type' => 'identity',
+      'title_label' => 'Title',
+      'body_label' => '',
+      'node_options[promote]' => 0,
+      'content_profile_use' => 1,
+    );
     $this->drupalPost('admin/content/types/add', $edit, t('Save content type'));
 
-    // create First Name field
-    $edit = array('_add_new_field[label]' => 'First Name', '_add_new_field[field_name]' => 'first_name', '_add_new_field[type]' => 'text', '_add_new_field[widget_type]' => 'text_textfield'); 
+    // Create First Name field.
+    $edit = array(
+      '_add_new_field[label]' => 'First Name',
+      '_add_new_field[field_name]' => 'first_name',
+      '_add_new_field[type]' => 'text',
+      '_add_new_field[widget_type]' => 'text_textfield',
+    );
     $this->drupalPost('admin/content/node-type/identity/fields', $edit, t('Save'));
 
-    $edit = array('required' => 1); 
+    $edit = array('required' => 1);
     $this->drupalPost('admin/content/node-type/identity/fields/field_first_name', $edit, t('Save field settings'));
 
-    // create Last Name field
-    $edit = array('_add_new_field[label]' => 'Last Name', '_add_new_field[field_name]'=> 'last_name', '_add_new_field[type]' => 'text', '_add_new_field[widget_type]' => 'text_textfield'); 
+    // Create Last Name field.
+    $edit = array(
+      '_add_new_field[label]' => 'Last Name',
+      '_add_new_field[field_name]' => 'last_name',
+      '_add_new_field[type]' => 'text',
+      '_add_new_field[widget_type]' => 'text_textfield',
+    );
     $this->drupalPost('admin/content/node-type/identity/fields', $edit, t('Save'));
 
-    $edit = array('required' => 1); 
+    $edit = array('required' => 1);
     $this->drupalPost('admin/content/node-type/identity/fields/field_last_name', $edit, t('Save field settings'));
 
-    // create Biography content type
-    $edit = array('name' => 'Biography', 'type' => 'biography', 'title_label' => 'Title', 'body_label' => '', 'node_options[promote]' => 0, 'content_profile_use' => 1); 
+    // Create Biography content type.
+    $edit = array(
+      'name' => 'Biography',
+      'type' => 'biography',
+      'title_label' => 'Title',
+      'body_label' => '',
+      'node_options[promote]' => 0,
+      'content_profile_use' => 1,
+    );
     $this->drupalPost('admin/content/types/add', $edit, t('Save content type'));
-    
-    // create CV field
-    $edit = array('_add_new_field[label]' => 'CV', '_add_new_field[field_name]' => 'cv', '_add_new_field[type]' => 'text', '_add_new_field[widget_type]' => 'text_textarea'); 
+
+    // Create CV field.
+    $edit = array(
+      '_add_new_field[label]' => 'CV',
+      '_add_new_field[field_name]' => 'cv',
+      '_add_new_field[type]' => 'text',
+      '_add_new_field[widget_type]' => 'text_textarea',
+    );
     $this->drupalPost('admin/content/node-type/biography/fields', $edit, t('Save'));
 
-    $edit = array('required' => 1, 'rows' => 5); 
+    $edit = array('required' => 1, 'rows' => 5);
     $this->drupalPost('admin/content/node-type/biography/fields/field_cv', $edit, t('Save field settings'));
 
-    // create Blog field (URL)
-    $edit = array('_add_new_field[label]' => 'Blog', '_add_new_field[field_name]' => 'blog', '_add_new_field[type]' => 'link', '_add_new_field[widget_type]' => 'link'); 
-    $this->drupalPost('admin/content/node-type/biography/fields', $edit, t('Save')); 
-    
-    // create Birthday field (date)
-    $edit = array('_add_new_field[label]' => 'Birthday', '_add_new_field[field_name]' => 'birthday', '_add_new_field[type]' => 'datestamp', '_add_new_field[widget_type]' => 'date_text'); 
+    // Create Blog field (URL).
+    $edit = array(
+      '_add_new_field[label]' => 'Blog',
+      '_add_new_field[field_name]' => 'blog',
+      '_add_new_field[type]' => 'link',
+      '_add_new_field[widget_type]' => 'link',
+    );
     $this->drupalPost('admin/content/node-type/biography/fields', $edit, t('Save'));
-    
-    // create Interests Vocabulary
-    $edit = array('name' => 'Interests', 'nodes[biography]' => 'biography', 'tags' => 1); 
+
+    // Create Birthday field (date).
+    $edit = array(
+      '_add_new_field[label]' => 'Birthday',
+      '_add_new_field[field_name]' => 'birthday',
+      '_add_new_field[type]' => 'datestamp',
+      '_add_new_field[widget_type]' => 'date_text',
+    );
+    $this->drupalPost('admin/content/node-type/biography/fields', $edit, t('Save'));
+
+    // Create Interests Vocabulary.
+    $edit = array(
+      'name' => 'Interests',
+      'nodes[biography]' => 'biography',
+      'tags' => 1,
+    );
     $this->drupalPost('admin/content/taxonomy/add/vocabulary', $edit, t('Save'));
 
     $vocabularies = taxonomy_get_vocabularies('biography');
-    
+
     foreach ($vocabularies as $vocabulary) {
       $this->vocabulary_id = $vocabulary->vid;
     }
-    
-    // create Contact Details contact type
-    $edit = array('name' => 'Contact Details', 'type' => 'contact_details', 'title_label' => 'Title', 'body_label' => '', 'node_options[promote]' => 0, 'content_profile_use' => 1); 
+
+    // Create Contact Details contact type.
+    $edit = array(
+      'name' => 'Contact Details',
+      'type' => 'contact_details',
+      'title_label' => 'Title',
+      'body_label' => '',
+      'node_options[promote]' => 0,
+      'content_profile_use' => 1,
+    );
     $this->drupalPost('admin/content/types/add', $edit, t('Save content type'));
-    
-    // create Can Be Contacted field
-    $edit = array('_add_new_field[label]' => 'Contact', '_add_new_field[field_name]' => 'can_be_contacted', '_add_new_field[type]' => 'number_integer', '_add_new_field[widget_type]' => 'optionwidgets_onoff'); 
+
+    // Create Can Be Contacted field.
+    $edit = array(
+      '_add_new_field[label]' => 'Contact',
+      '_add_new_field[field_name]' => 'can_be_contacted',
+      '_add_new_field[type]' => 'number_integer',
+      '_add_new_field[widget_type]' => 'optionwidgets_onoff',
+    );
     $this->drupalPost('admin/content/node-type/contact-details/fields', $edit, t('Save'));
- 
-    $edit = array('allowed_values' => "0
-    1|Can be contacted"); 
+
+    $edit = array(
+      'allowed_values' => "0
+      1|Can be contacted",
+    );
     $this->drupalPost('admin/content/node-type/contact-details/fields/field_can_be_contacted', $edit, t('Save field settings'));
-    
-    // create Contact Preference field
-    $edit = array('_add_new_field[label]' => 'Contact Preference', '_add_new_field[field_name]' => 'contact_preference', '_add_new_field[type]' => 'text', '_add_new_field[widget_type]' => 'optionwidgets_select'); 
+
+    // Create Contact Preference field.
+    $edit = array(
+      '_add_new_field[label]' => 'Contact Preference',
+      '_add_new_field[field_name]' => 'contact_preference',
+      '_add_new_field[type]' => 'text',
+      '_add_new_field[widget_type]' => 'optionwidgets_select',
+    );
     $this->drupalPost('admin/content/node-type/contact-details/fields', $edit, t('Save'));
 
-    $edit = array('allowed_values' => 'email|email
-    telephone|telephone
-    post|post'); 
+    $edit = array(
+      'allowed_values' => 'email|email
+      telephone|telephone
+      post|post',
+    );
     $this->drupalPost('admin/content/node-type/contact-details/fields/field_contact_preference', $edit, t('Save field settings'));
 
-    // set access perm for authenticated users to creade profile nodes
-    $edit = array('2[create identity content]' => 'create identity content', '2[create biography content]' => 'create biography content', '2[create contact_details content]' => 'create contact_details content');
-    $this->drupalPost('admin/user/permissions', $edit, t('Save permissions')); 
+    // Set access perm for authenticated users to create profile nodes.
+    $edit = array(
+      '2[create identity content]' => 'create identity content',
+      '2[create biography content]' => 'create biography content',
+      '2[create contact_details content]' => 'create contact_details content',
+    );
+    $this->drupalPost('admin/user/permissions', $edit, t('Save permissions'));
   }
 
 
   /**
-   *  Match CSV columns to Profile fields
+   * Match CSV columns to Profile fields.
    */
   function settingsNodeprofileMatch(&$edit) {
-    $edit['field_match[0][field_match]'] = 'content_profile-identity cck:field_first_name:value'; // First Name
-    $edit['field_match[1][field_match]'] = 'content_profile-identity cck:field_last_name:value'; // Last Name 
-    $edit['field_match[10][field_match]'] = 'content_profile-biography cck:field_cv:value'; // CV 
-    $edit['field_match[7][field_match]'] = 'content_profile-contact_details cck:field_can_be_contacted:value'; // Contact Permision   
-    $edit['field_match[8][field_match]'] = 'content_profile-contact_details cck:field_contact_preference:value'; // Contact Preference
-//    $edit['field_match[9][field_match]'] = 'taxonomy-' . $this->vocabulary_id; // Interests       
-    $edit['field_match[6][field_match]'] = 'content_profile-biography cck:field_blog:url'; // Blog
-    $edit['field_match[11][field_match]'] = 'content_profile-biography cck:field_birthday:value'; // Birthday
+    // First Name.
+    $edit['field_match[0][field_match]'] = 'content_profile-identity cck:field_first_name:value';
+    // Last Name.
+    $edit['field_match[1][field_match]'] = 'content_profile-identity cck:field_last_name:value';
+    // CV.
+    $edit['field_match[10][field_match]'] = 'content_profile-biography cck:field_cv:value';
+    // Contact Permission.
+    $edit['field_match[7][field_match]'] = 'content_profile-contact_details cck:field_can_be_contacted:value';
+    // Contact Preference.
+    $edit['field_match[8][field_match]'] = 'content_profile-contact_details cck:field_contact_preference:value';
+    // Interests.
+    // $edit['field_match[9][field_match]'] = 'taxonomy-'.$this->vocabulary_id;
+    // Blog.
+    $edit['field_match[6][field_match]'] = 'content_profile-biography cck:field_blog:url';
+    // Birthday.
+    $edit['field_match[11][field_match]'] = 'content_profile-biography cck:field_birthday:value';
   }
 
   /**
-   *  Check data in CSV file matches data in profiles
+   * Check data in CSV file matches data in profiles.
    */
   function checkNodeprofileExist() {
     $file_path = drupal_get_path('module', 'user_import') . '/sample.txt';
     $handle = @fopen($file_path, "r");
     $row = 0;
 
-    while ($csv = fgetcsv($handle, 1000, ',')) { 
-     
+    while ($csv = fgetcsv($handle, 1000, ',')) {
+
       if ($row > 0) {
-	
-        $user = user_load(array('mail' => $csv[5])); 
-        // test each data cell against nodeprofile field content
+
+        $user = user_load(array('mail' => $csv[5]));
+        // Test each data cell against nodeprofile field content.
         $identity = node_load(array('type' => 'identity', 'uid' => $user->uid), NULL, TRUE);
         $this->drupalGet("node/$identity->nid");
         $this->assertText(check_plain($csv[0]), "[Compare CSV and Profile data] Row: $row Field: First Name");
@@ -346,73 +441,65 @@ class UserImportNodeprofileTestCase extends UserImportWebTestCase {
         $birthday = format_date(strtotime($csv[11]), 'custom', 'D, j/m/Y');
         $this->assertText($birthday, "[Compare CSV and Profile data] Row: $row Field: Birthday " . $birthday);
 
-
         $contact_details = node_load(array('type' => 'contact_details', 'uid' => $user->uid), NULL, TRUE);
         $this->drupalGet("node/$contact_details->nid");
 
         if (isset($csv[7]) && !empty($csv[7])) {
-					$this->assertText('Can be contacted', "[Compare CSV and Profile data] Row: $row Field: Contact Permission set");
-				}
-				else {
-					$this->assertNoText('Can be contacted', "[Compare CSV and Profile data] Row: $row Field: Contact Permission not set");
-				}
+          $this->assertText('Can be contacted', "[Compare CSV and Profile data] Row: $row Field: Contact Permission set");
+        }
+        else {
+          $this->assertNoText('Can be contacted', "[Compare CSV and Profile data] Row: $row Field: Contact Permission not set");
+        }
 
-				$this->assertText($csv[8], "[Compare CSV and Profile data] Row: $row Field: Contact Preference");
-        
-        //test interests link on profile page
+        $this->assertText($csv[8], "[Compare CSV and Profile data] Row: $row Field: Contact Preference");
+
+        // Test interests link on profile page.
         if (!empty($user->profile_interests)) {
           $interests = explode(',', $user->profile_interests);
           $this->drupalGet('profile/profile_interests/' . $interests[0]);
-          $this->assertWantedRaw('<a title="View user profile." href="/' . url('user/' . $user->uid) . '">' . $user->name . '</a>' , '[Freeform List] User is listed on page about item in list');
-        }  
-        
+          $this->assertWantedRaw('<a title="View user profile." href="/' . url('user/' . $user->uid) . '">' . $user->name . '</a>', '[Freeform List] User is listed on page about item in list');
+        }
+
       }
-      
+
       $row++;
     }
-    
+
   }
-  
+
   /**
    * SimpleTest core method: code run after each and every test method.
-  */
+   */
   function tearDown() {
 
-    // delete accounts of users imported
+    // Delete accounts of users imported.
     $users_email = $this->usersList();
 
     foreach ($users_email as $mail) {
       $account = user_load(array('mail' => $mail));
-      // delete node profile nodes
+      // Delete node profile nodes.
       if (!empty($account)) {
         $identity = node_load(array('type' => 'identity', 'uid' => $account->uid));
         $biography = node_load(array('type' => 'biography', 'uid' => $account->uid));
         $contact_details = node_load(array('type' => 'contact_details', 'uid' => $account->uid));
         node_delete($identity->nid);
-        node_delete($biography->nid); 
+        node_delete($biography->nid);
         node_delete($contact_details->nid);
-        user_delete(array(), $account->uid);  
-      }  
+        user_delete(array(), $account->uid);
+      }
     }
-    
-    // delete the import
-    $import_id = $this->importID();   
-    $this->assertTrue(!empty($import_id), t('Import ID: !id', array('!id' => $import_id))); 
+
+    // Delete the import.
+    $import_id = $this->importID();
+    $this->assertTrue(!empty($import_id), t('Import ID: !id', array('!id' => $import_id)));
     _user_import_settings_deletion($import_id);
-  
-    // delete vocabulary
+
+    // Delete vocabulary.
     taxonomy_del_vocabulary($this->vocabulary_id);
- 
-    // uninstall modules
-    // - tear down disable doesn't seem to do this 
-    // foreach($this->modules as $module) {
-    //   if (function_exists($module . '_uninstall')) { 
-    //     $result = call_user_func_array($module . '_uninstall', array());
-    //   } 
-    // }  
-    
-    // delete nodeprofile content types 
-    node_type_delete('dummy'); // (for some reason) the first node_type_delete is completely ignored
+
+    // Delete nodeprofile content types.
+    // The first node_type_delete is completely ignored.
+    node_type_delete('dummy');
     node_type_delete('identity');
     node_type_delete('biography');
     node_type_delete('contact_details');
@@ -423,8 +510,8 @@ class UserImportNodeprofileTestCase extends UserImportWebTestCase {
 }
 
 /**
- *  Test import of user data into Profile module
- */ 
+ * Test import of user data into Profile module.
+ */
 class UserImportProfileTestCase extends UserImportWebTestCase {
 
 
@@ -437,154 +524,199 @@ class UserImportProfileTestCase extends UserImportWebTestCase {
   }
 
   function setUp() {
-  			parent::setUp('user_import', 'profile');
-  	    $this->admin_user = $this->drupalCreateUser(array('administer users', 'access administration pages', 'administer site configuration'));
-  	    $this->user_importer = $this->drupalCreateUser(array('import users'));
-  } 
-	
+    parent::setUp('user_import', 'profile');
+    $this->admin_user = $this->drupalCreateUser(array(
+      'administer users',
+      'access administration pages',
+      'administer site configuration',
+    ));
+    $this->user_importer = $this->drupalCreateUser(array('import users'));
+  }
+
   /**
-   *  User with right permissions creates import (with new settings)
-   *  - test import of user data into Profile module
+   * User with right permissions creates import with new settings.
+   *
+   * Test import of user data into Profile module.
    */
   function testCreateImport() {
     $this->drupalLogin($this->admin_user);
     $this->profileFieldsCreate();
-      
-    // Prepare a user to do testing 
-    $this->drupalGet('logout'); // log out first
+
+    // Prepare a user to do testing.
+    $this->drupalGet('logout');
     $this->drupalLogin($this->user_importer);
-  
-    // Select CSV file (the included example file)
+
+    // Select CSV file (the included example file).
     $this->settingsFileSelect();
-  
-    // import settings 
-		$this->importID($this->getUrl()); // store import ID for later
- 
+
+    // Import settings, store import ID for later.
+    $this->importID($this->getUrl());
+
     $settings = array();
     $this->settingsEmailMatch($settings);
     $this->settingsProfileMatch($settings);
     $this->settingsIgnoreFirstLine($settings);
     $this->drupalPost($this->getUrl(), $settings, 'Import');
-  
-    // check if users have been imported
+
+    // Check if users have been imported.
     $this->checkProfileExist();
   }
-   
+
   /**
-   *  create profile fields
+   * Create profile fields.
    */
-  function profileFieldsCreate() {  
-    
-    // Textfield
-    $edit = array('category' => 'Name', 'title' => 'First Name', 'name' => 'profile_first_name'); 
+  function profileFieldsCreate() {
+
+    // Textfield.
+    $edit = array(
+      'category' => 'Name',
+      'title' => 'First Name',
+      'name' => 'profile_first_name',
+    );
     $this->drupalPost('admin/user/profile/add/textfield', $edit, t('Save field'));
-  
-    // Textfield 
-    $edit = array('category' => 'Name', 'title' => 'Last Name', 'name' => 'profile_last_name'); 
+
+    // Textfield.
+    $edit = array(
+      'category' => 'Name',
+      'title' => 'Last Name',
+      'name' => 'profile_last_name',
+    );
     $this->drupalPost('admin/user/profile/add/textfield', $edit, t('Save field'));
-  
-    // Textarea
-    $edit = array('category' => 'Biography', 'title' => 'CV', 'name' => 'profile_cv'); 
+
+    // Textarea.
+    $edit = array(
+      'category' => 'Biography',
+      'title' => 'CV',
+      'name' => 'profile_cv',
+    );
     $this->drupalPost('admin/user/profile/add/textarea', $edit, t('Save field'));
-  
-    // Checkbox
-    $edit = array('category' => 'Contact Details', 'title' => 'Can Be Contacted', 'name' => 'profile_contact_permission'); 
+
+    // Checkbox.
+    $edit = array(
+      'category' => 'Contact Details',
+      'title' => 'Can Be Contacted',
+      'name' => 'profile_contact_permission',
+    );
     $this->drupalPost('admin/user/profile/add/checkbox', $edit, t('Save field'));
-  
-    // List
-    $edit = array('category' => 'Contact Details', 'title' => 'Contact Preference', 'name' => 'profile_contact_preference', 'options' => 'email,telephone,post'); 
+
+    // List.
+    $edit = array(
+      'category' => 'Contact Details',
+      'title' => 'Contact Preference',
+      'name' => 'profile_contact_preference',
+      'options' => 'email,telephone,post',
+    );
     $this->drupalPost('admin/user/profile/add/selection', $edit, t('Save field'));
-  
-    // Freeform List
-    $edit = array('category' => 'Biography', 'title' => 'Interests', 'name' => 'profile_interests'); 
-    $this->drupalPost('admin/user/profile/add/list', $edit, t('Save field'));  
-  
-    // URL
-    $edit = array('category' => 'Biography', 'title' => 'Blog', 'name' => 'profile_blog'); 
-    $this->drupalPost('admin/user/profile/add/url', $edit, t('Save field')); 
-  
-    // Date
-    $edit = array('category' => 'Biography', 'title' => 'Birthday', 'name' => 'profile_birthday'); 
+
+    // Freeform List.
+    $edit = array(
+      'category' => 'Biography',
+      'title' => 'Interests',
+      'name' => 'profile_interests',
+    );
+    $this->drupalPost('admin/user/profile/add/list', $edit, t('Save field'));
+
+    // URL.
+    $edit = array(
+      'category' => 'Biography',
+      'title' => 'Blog',
+      'name' => 'profile_blog',
+    );
+    $this->drupalPost('admin/user/profile/add/url', $edit, t('Save field'));
+
+    // Date.
+    $edit = array(
+      'category' => 'Biography',
+      'title' => 'Birthday',
+      'name' => 'profile_birthday',
+    );
     $this->drupalPost('admin/user/profile/add/date', $edit, t('Save field'));
-  } 
-  
+  }
+
   /**
-   *  Match CSV columns to Profile fields
+   *  Match CSV columns to Profile fields.
    */
   function settingsProfileMatch(&$edit) {
-    $edit['field_match[0][field_match]'] = 'profile-1'; // First Name
-    $edit['field_match[1][field_match]'] = 'profile-2'; // Last Name 
-    $edit['field_match[10][field_match]'] = 'profile-3'; // CV 
-    $edit['field_match[7][field_match]'] = 'profile-4'; // Contact Permision  
-    $edit['field_match[8][field_match]'] = 'profile-5'; // Contact Preference
-    $edit['field_match[9][field_match]'] = 'profile-6'; // Interests        
-    $edit['field_match[6][field_match]'] = 'profile-7'; // Blog
-    $edit['field_match[11][field_match]'] = 'profile-8'; // Birthday
+    // First Name.
+    $edit['field_match[0][field_match]'] = 'profile-1';
+    // Last Name.
+    $edit['field_match[1][field_match]'] = 'profile-2';
+    // CV.
+    $edit['field_match[10][field_match]'] = 'profile-3';
+    // Contact Permission.
+    $edit['field_match[7][field_match]'] = 'profile-4';
+    // Contact Preference.
+    $edit['field_match[8][field_match]'] = 'profile-5';
+    // Interests.
+    $edit['field_match[9][field_match]'] = 'profile-6';
+    // Blog.
+    $edit['field_match[6][field_match]'] = 'profile-7';
+    // Birthday.
+    $edit['field_match[11][field_match]'] = 'profile-8';
   }
-    
+
   /**
-   *  Check data in CSV file matches data in profiles
+   * Check data in CSV file matches data in profiles.
    */
   function checkProfileExist() {
 
     $file_path = drupal_get_path('module', 'user_import') . '/sample.txt';
     $handle = @fopen($file_path, "r");
     $row = 0;
-  
-    while ($csv = fgetcsv($handle, 1000, ',')) { 
-			  
+
+    while ($csv = fgetcsv($handle, 1000, ',')) {
+
       if ($row > 0) {
-        $user = user_load(array('mail' => $csv[5])); 
-        // test each data cell against Profile field content   
-				$profile_first_name = isset($user->profile_first_name) ? $user->profile_first_name : '';  
+        $user = user_load(array('mail' => $csv[5]));
+        // Test each data cell against Profile field content.
+        $profile_first_name = isset($user->profile_first_name) ? $user->profile_first_name : '';
         $this->assertEqual($profile_first_name, $csv[0], "[Compare CSV data to Profile data] Row: $row Field: First Name");
 
-				$profile_last_name = isset($user->profile_last_name) ? $user->profile_last_name : '';
-				$this->assertEqual($profile_last_name, $csv[1], "[Compare CSV data to Profile data] Row: $row Field: Last Name");
-				
-				$profile_blog = isset($user->profile_blog) ? $user->profile_blog : ''; 
+        $profile_last_name = isset($user->profile_last_name) ? $user->profile_last_name : '';
+        $this->assertEqual($profile_last_name, $csv[1], "[Compare CSV data to Profile data] Row: $row Field: Last Name");
+
+        $profile_blog = isset($user->profile_blog) ? $user->profile_blog : '';
         $this->assertEqual($profile_blog, $csv[6], "[Compare CSV data to Profile data] Row: $row Field: Blog");
 
-				$profile_contact_permission = isset($user->profile_contact_permission) ? $user->profile_contact_permission : '';
-				$file_field_value = (!isset($csv[7]) || empty($csv[7])) ? 0 : 1;
-				$this->assertEqual($profile_contact_permission, $file_field_value, "[Compare CSV data to Profile data] Row: $row Field: Contact Permission");
-                                                                                                                                  
-				$profile_contact_preference = isset($user->profile_contact_preference) ? $user->profile_contact_preference : '';
-				$this->assertEqual($profile_contact_preference, $csv[8], "[Compare CSV data to Profile data] Row: $row Field: Contact Preference");
-				
-				$profile_interests = isset($user->profile_interests) ? $user->profile_interests : '';
+        $profile_contact_permission = isset($user->profile_contact_permission) ? $user->profile_contact_permission : '';
+        $file_field_value = (!isset($csv[7]) || empty($csv[7])) ? 0 : 1;
+        $this->assertEqual($profile_contact_permission, $file_field_value, "[Compare CSV data to Profile data] Row: $row Field: Contact Permission");
+
+        $profile_contact_preference = isset($user->profile_contact_preference) ? $user->profile_contact_preference : '';
+        $this->assertEqual($profile_contact_preference, $csv[8], "[Compare CSV data to Profile data] Row: $row Field: Contact Preference");
+
+        $profile_interests = isset($user->profile_interests) ? $user->profile_interests : '';
         $this->assertEqual($profile_interests, $csv[9], "[Compare CSV data to Profile data] Row: $row Field: Profile Interests");
 
-				$profile_cv = isset($user->profile_cv) ? $user->profile_cv : '';
-				$this->assertEqual($profile_cv, $csv[10], "[Compare CSV data to Profile data] Row: $row Field: CV");
+        $profile_cv = isset($user->profile_cv) ? $user->profile_cv : '';
+        $this->assertEqual($profile_cv, $csv[10], "[Compare CSV data to Profile data] Row: $row Field: CV");
 
         $profile_birthday = isset($user->profile_birthday) ? implode('/', $user->profile_birthday) : '';
-        
-				if (isset($user->profile_birthday)) {
-					$profile_birthday = $user->profile_birthday['month'] .'/'. $user->profile_birthday['day'] .'/'. $user->profile_birthday['year'];
-				}
-				else {
-					$profile_birthday = '';
-				}
+
+        if (isset($user->profile_birthday)) {
+          $profile_birthday = $user->profile_birthday['month'] . '/' . $user->profile_birthday['day'] . '/' . $user->profile_birthday['year'];
+        }
+        else {
+          $profile_birthday = '';
+        }
 
         $this->assertEqual($profile_birthday, $csv[11], "[Compare CSV data to Profile data] Row: $row Field: Birthday");
-        /**
-         * @todo test below fails because it gets an access denied message.
-         */
-        //test interests link on profile page
-        // if (!empty($user->profile_interests)) {
-        //   $interests = explode(',', $user->profile_interests);
-        //   $this->drupalGet('profile/profile_interests/' . $interests[0]);
-        //   $this->assertRaw('<a title="View user profile." href="/'. url('user/'. $user->uid) .'">'. $user->name .'</a>', '[Freeform List] User is listed on page about item in list');
-        // }  
-        
+
+        // @todo test below fails because it gets an access denied message.
+        /*
+        test interests link on profile page
+        if (!empty($user->profile_interests)) {
+        $interests = explode(',', $user->profile_interests);
+        $this->drupalGet('profile/profile_interests/' . $interests[0]);
+        $this->assertRaw('<a title="View user profile." href="/'. url('user/
+        ' . $user->uid) .'">'. $user->name .'</a>',
+        '[Freeform List] User is listed on page about item in list');
+        }
+        */
+
       }
-      
+
       $row++;
     }
-  }                   
-
+  }
 }
-
- 
-
