diff --git a/webserver_auth.module b/webserver_auth.module
index e3ea513..ad4214f 100644
--- a/webserver_auth.module
+++ b/webserver_auth.module
@@ -1,13 +1,17 @@
 <?php
-// $Id: webserver_auth.module,v 1.22.2.1 2008/08/07 16:38:49 weitzman Exp $
+/**
+ * @file
+ * The Webserver Auth Module
+ *
+ * This module manages automatic web server user login and logout.
+ */
 
 /**
  * Implements hook_menu().
  */
 function webserver_auth_menu() {
   $items = array();
-  $items['admin/config/people/webserver_auth'] = array
-  (
+  $items['admin/config/people/webserver_auth'] = array(
     'title' => t('Webserver authentication'),
     'description' => t('Configure a domain for generating email addresses. Optional.'),
     'page callback' => 'drupal_get_form',
@@ -23,65 +27,71 @@ function webserver_auth_menu() {
 function webserver_auth_init() {
   global $user, $language;
    
-  // first we simply check if the user has been logged in by Drupal already.  If they have, we're done.
-  if (isset($user->uid) && ($user->uid != 0))
-  {
+  // First we simply check if the user has been logged in by Drupal already.
+  // If they have, we're done.
+  if (isset($user->uid) && ($user->uid != 0)) {
     return;
   }
-  // get the login name from the $_SERVER variable.
+  // Get the login name from the $_SERVER variable.
   $authname = '';
-  if (isset ($_SERVER ['REDIRECT_REMOTE_USER'])) $authname = $_SERVER ['REDIRECT_REMOTE_USER'];
-  elseif (isset ($_SERVER ['REMOTE_USER'])) $authname = $_SERVER ['REMOTE_USER'];
  
-  if ($authname)
-  {
+  if (isset ($_SERVER ['REDIRECT_REMOTE_USER'])) {
+    $authname = $_SERVER ['REDIRECT_REMOTE_USER'];
+  }
+  elseif (isset ($_SERVER ['REMOTE_USER'])) {
+    $authname = $_SERVER ['REMOTE_USER'];
+  }
+
+  if ($authname) {
     $authname = webserver_auth_prepare_username($authname);
       
-    if (webserver_auth_attempt_login($authname))
-    {
+    if (webserver_auth_attempt_login($authname)) {
       return;
     }
-    else
-    {
-      // we didn't fnd the user so we create an account for them if set to do so.
-      // note, hook_user_presave() is called during this process. 
+    else {
+      // We didn't fnd the user so we create an account for them if set to do
+      // so. Note, hook_user_presave() is called during this process.
       // That's where we modify the user account to add email etc.
-      if (variable_get('webserver_auth_create_user', TRUE))
-      {
-        try
-        {
+      if (variable_get('webserver_auth_create_user', TRUE)) {
+        try {
           user_external_login_register($authname, 'webserver_auth');
           
-          // user_external_login_register appears to register the user but not actually log them in
-          // in order to do that we need to forward the user to a new page completely
+          // User_external_login_register appears to register the user but not
+          // actually log them in in order to do that we need to forward the
+          // user to a new page completely.
           drupal_goto(current_path());
         }
-        catch(PDOException $e)
-        {
+        catch(PDOException $e) {
           watchdog('webserver_auth', 'unable to create new user record for user: ' . $authname . '.  This is probably because they already exist in the user table but not in the authmap table for webserver_auth.');
           return;
         }
       }
     }
    
-    // still here?
-    watchdog('webserver_auth', 'user: ' . $authname . ' does not exist in the database or is not included in the authmap table for webserver_auth and cannot login.');
+    // Still here?
+    watchdog('webserver_auth', 'user: @authname does not exist in the database or is not included in the authmap table for webserver_auth and cannot login.', array('@authname' => $authname));
   }
-  else
-  {
+  else {
     watchdog('webserver_auth', 'No authname');
   }
   return;
 }
 
-function webserver_auth_attempt_login($preparedauthname)
-{
-  // can we find the user in the db already?
+/**
+ * Attempts to log the user in.
+ *
+ * @param $preparedauthname
+ *   Authname prepared to attempt match in authmap db table.
+ *
+ * @return
+ *   Boolean whether user is found and logged in or not.
+ */
+function webserver_auth_attempt_login($preparedauthname) {
+  // Can we find the user in the db already?
   $uid = db_query('SELECT uid FROM {authmap} WHERE lower(authname) = lower(:authname) AND module = :module', array (':authname' => $preparedauthname, ':module' => 'webserver_auth')) -> fetchField ();
 
-  if (is_numeric($uid))
-  {
-    // we found the user so just log them in
+  if (is_numeric($uid)) {
+    // We found the user so just log them in.
     $form_state['uid'] = $uid;
     user_login_submit(array(), $form_state);
     return true;
@@ -90,34 +100,42 @@ function webserver_auth_attempt_login($preparedauthname)
 }
 
 /*
-* Implements hook_user_presave
+* Implements hook_user_presave().
 */
 function webserver_auth_user_presave(&$edit, $account, $category) {
   global $user;
  
-  if (!isset($edit['mail']))
-  {
-    if ($domain = variable_get('webserver_auth_email_domain', ''))
-    {
-      // create the email address by concatenating the name and domain (if there is one)
-      // ensure we don't get double @ by removing them from the domain first.
+  if (!isset($edit['mail'])) {
+    if ($domain = variable_get('webserver_auth_email_domain', '')) {
+      // Create the email address by concatenating the name and domain (if there
+      // is one) ensure we don't get double @ by removing them from the domain
+      // first.
       $edit['mail'] = strtolower($edit['name'] . '@' . str_replace('@', '', $domain));
      
-      // replace any spaces with dots
+      // Replace any spaces with dots.
       $edit['mail'] = str_replace(' ', '.', $edit['mail']);
     }
   }
 }
 
+/**
+ * Implements hook_user_insert().
+ */
 function webserver_auth_user_insert(&$edit, $account, $category) {
   if ($code = variable_get('webserver_auth_insert', '')) eval('?>'. $code);
 }
 
+/**
+ * Implements hook_user_logout().
+ */
 function webserver_auth_user_logout($account) {
   global $base_url;
   $base_url = str_replace('https://', 'http://', $base_url);
 }
 
+/**
+ * Webserver_auth admin settings form.
+ */
 function webserver_auth_settings() {
   $form = array();
   $form['webserver_auth_create_user'] = array(
@@ -176,18 +194,19 @@ ef=\"http://api.drupal.org/api/function/hook_user/7\">hook_user('insert',...)</a
 }
 
 /**
-  * Implementation of hook form_FORM_ID_alter
+ * Implements of hook_form_FORM_ID_alter().
+ *
   * FORM_ID = user_profile_form
   * We are going to disable the ability to change passwords and usernames!
   */
 function webserver_auth_form_user_profile_form_alter(&$form, &$form_state, $form_id) {
-  //disable option to change username and give reason why
+  // Disable option to change username and give reason why.
   if (variable_get('webserver_auth_disallow_username_change', FALSE)) {
     $form['account']['name']['#disabled'] = TRUE;
     $form['account']['name']['#description'] = t('This value has been set by default from the browser login and cannot be changed.');
   }
 
-  //disable password fields and checking on user account edits
+  // Disable password fields and checking on user account edits.
   if (variable_get('webserver_auth_disallow_pw_change', FALSE)) {
     unset($form['account']['pass']);
     unset($form['account']['current_pass']);
@@ -196,13 +215,11 @@ function webserver_auth_form_user_profile_form_alter(&$form, &$form_state, $form
   }
 }
 
-/*
+/**
  * Strip the prefix and suffix from the username according to the settings.
  */
-function webserver_auth_prepare_username($username)
-{
-  if (variable_get('webserver_auth_strip_prefix', TRUE))
-  {
+function webserver_auth_prepare_username($username) {
+  if (variable_get('webserver_auth_strip_prefix', TRUE)) {
     $fields = explode("\\", $username);
     $username = $fields [count ($fields) - 1];
   }
