diff --git a/cosign.module b/cosign.module
index b27e891..bb8f2bc 100644
--- a/cosign.module
+++ b/cosign.module
@@ -7,25 +7,32 @@
  * This module manages automatic user login and supplies cosign logout bar.
  * It depends on the webserver auth module.
  */
+
+/**
+ * Implementation of hook_init().
+ */
 function cosign_init() {
   global $user;
 
+  //@TODO: Fix this. What if someone aliases logout?
   if ($_GET['q'] == 'logout') {
-    watchdog('cosign', "logout: %name",array('%name'=>$user->name));
+    watchdog('cosign', "logout: %name", array('%name' => $user->name));
     cosign_logout();
   }
   elseif ($user->uid) {
     // do nothing, user is logged in, and not logging out...
   }
   else {
-    watchdog('cosign', "login:  %name",array('%name'=>$user->name));
+    watchdog('cosign', "login:  %name", array('%name' => $user->name));
     webserver_auth_init();
   }
 
   return TRUE;
 }
 
-// Not a hook.  Defines the admin form which is referenced in the _menu hook.
+/*
+ * Page callback that defines the admin form.
+ */
 function cosign_admin() {
 
   $logout_machine = 'https://' . $_SERVER[ 'SERVER_NAME' ];
@@ -55,6 +62,9 @@ function cosign_admin() {
   return system_settings_form($form);
 }
 
+/**
+ * Implementation of hook_menu().
+ */
 function cosign_menu() {
   $items['admin/settings/cosign'] = array(
     'title' => 'Cosign',
@@ -68,18 +78,20 @@ function cosign_menu() {
   return $items;
 }
 
-
-function cosign_form_alter(&$form, $form_state, $form_id) {
+/**
+ * Implementation of hook_form_alter().
+ */
+function cosign_form_alter(&$form, &$form_state, $form_id) {
   if ($form_id == "user_register") {
     drupal_goto('https://' . $_SERVER['SERVER_NAME'] . base_path());
   }
 
   if ($form_id == "user_admin_settings") {
-    $form['registration']['#title'] = t( $form['registration']['#title'] ) . " (disabled by the cosign module) ";
+    $form['registration']['#title'] = t($form['registration']['#title']) . " (disabled by the cosign module) ";
     $form['registration']['#collapsible'] = TRUE;
     $form['registration']['#collapsed'] = TRUE;
     $form['registration']['user_register']['#default_value'] = 1;
-    $form['email']['#title'] = t( $form['email']['#title'] ) . " (disabled by the cosign module) ";
+    $form['email']['#title'] = t($form['email']['#title']) . " (disabled by the cosign module) ";
     $form['email']['#collapsible'] = TRUE;
     $form['email']['#collapsed'] = TRUE;
     foreach ($form['registration'] as $k => $item) {
@@ -107,12 +119,15 @@ function cosign_form_alter(&$form, $form_state, $form_id) {
 
   if ($form_id == "user_profile_form") {
     if (isset($form['account']['name'])) {
-      $form['account']['name']['#type']='hidden';
+      $form['account']['name']['#type'] = 'hidden';
     }
     unset($form['account']['pass']);
   }
 }
 
+/**
+ * Implementation of hook_help().
+ */
 function cosign_help($path, $arg) {
   switch ($path) {
     case 'admin/modules#description':
@@ -123,10 +138,13 @@ function cosign_help($path, $arg) {
   }
 }
 
+/**
+ * Logs a user out through cosign.
+ */
 function cosign_logout() {
   global $user;
 
-  watchdog('user','Session closed for %name.', array('%name' => $user->name));
+  watchdog('user', 'Session closed for %name.', array('%name' => $user->name));
 
   // Destroy the current session:
   session_destroy();
@@ -146,7 +164,10 @@ function cosign_logout() {
   return TRUE;
 }
 
-function cosign_block($op='list', $delta=0) {
+/**
+ * Implementation of hook_block().
+ */
+function cosign_block($op = 'list', $delta = 0) {
   global $user;
 
   switch ($op) {
@@ -165,20 +186,23 @@ function cosign_block($op='list', $delta=0) {
   return $block;
 }
 
-function cosign_disable() {
-  $module = 'cosign';
-
-  db_query("UPDATE {system} SET status = 0 WHERE type = 'module' AND name =
-    '%s'", $module);
+/**
+ * Utility function to disable the cosign module.
+ */
+function _cosign_disable() {
+  module_disable('cosign');
   drupal_set_message(t('Cosign module has been disabled'));
 }
 
+/**
+ * Implementation of hook_enable().
+ */
 function cosign_enable() {
   $errmsg = '';
   $realm = '';
 
-  if (isset($_SERVER[REMOTE_REALM])) {
-    $realm = '@' . $_SERVER[REMOTE_REALM];
+  if (isset($_SERVER['REMOTE_REALM'])) {
+    $realm = '@' . $_SERVER['REMOTE_REALM'];
   }
 
   // This is a fresh install, don't bother copying users
@@ -190,7 +214,7 @@ function cosign_enable() {
   // look for REMOTE_USER, only enable if it's set
   $cosign_user = $_SERVER['REMOTE_USER'];
   if (!isset($cosign_user) || empty($cosign_user)) {
-    cosign_disable();
+    _cosign_disable();
     drupal_error_handler(1, 'Could not detect your username from ' .
       '$_SERVER[\'REMOTE_USER\'], cosign was not enabled<br />',
       __FILE__, __LINE__, 0);
@@ -199,7 +223,7 @@ function cosign_enable() {
 
   // is REMOTE_USER registered as a local user?
   $sql = "SELECT uid, name FROM {users} WHERE name='%s'";
-  $local_result = db_query($sql,$cosign_user);
+  $local_result = db_query($sql, $cosign_user);
   $local_user = db_fetch_object($local_result);
 
   /*
@@ -208,14 +232,14 @@ function cosign_enable() {
    */
   if (empty($local_user)) {
     $del_sql = 'DELETE FROM {users} WHERE uid=1';
-    if (!(db_query($del_sql))) {
+    if (!db_query($del_sql)) {
       $errmsg .= 'unable to delete old admin user ';
     }
 
     $ins_sql = 'INSERT INTO {users} (uid, name, mail, created, status) ' .
       "values(1, '$_SERVER[REMOTE_USER]', '$_SERVER[REMOTE_USER]$realm', " .
       time() . ', 1)';
-    if (!(db_query($ins_sql))) {
+    if (!db_query($ins_sql)) {
       $errmsg .= 'unable to create new admin user ';
     }
   }
@@ -225,12 +249,12 @@ function cosign_enable() {
    */
   elseif ($local_user->uid != 1) {
     $del_sql = 'DELETE FROM {users} WHERE uid=1';
-    if (!(db_query($del_sql))) {
+    if (!db_query($del_sql)) {
       $errmsg .= 'unable to delete old admin user ';
     }
 
     $upd_sql = "UPDATE {users} SET uid=1 WHERE name='%s'";
-    if (!(db_query($upd_sql,$_SERVER['REMOTE_USER']))) {
+    if (!db_query($upd_sql, $_SERVER['REMOTE_USER'])) {
       $errmsg .= 'unable to update your user to admin ';
     }
   }
@@ -238,7 +262,7 @@ function cosign_enable() {
   if (!empty($errmsg)) {
     drupal_set_message(
       t("There was an error when initializing cosign: $errmsg"));
-    cosign_disable();
+    _cosign_disable();
     return FALSE;
   }
 
