diff --git a/js/watcher.js b/js/watcher.js
index 47ab69b..d3550dd 100644
--- a/js/watcher.js
+++ b/js/watcher.js
@@ -7,20 +7,22 @@
 /**
  * Register Watcher behavior
  */
-Drupal.behaviors.watcher = function (context) {
-	$('.watcher_binder_send_email_status_icon:not(.watcher-processed)', context)
-    .click( function () { 
-      ajaxToggleEmailNotifications(this, this.href); 
-      return false;
-    })
-		.addClass('watcher-processed');
-  $('.watcher_node_toggle_watching_link:not(.watcher-processed)', context)
-    .click( function () {
-      ajaxToggleWatchFade(this, this.href);
-      return false;
-    })
-		.addClass('watcher-processed');
-}
+Drupal.behaviors.watcher = {
+  attach: function (context) {
+    $('.watcher_binder_send_email_status_icon:not(.watcher-processed)', context)
+      .click( function () { 
+        ajaxToggleEmailNotifications(this, this.href); 
+        return false;
+      })
+      .addClass('watcher-processed');
+    $('.watcher_node_toggle_watching_link:not(.watcher-processed)', context)
+      .click( function () {
+        ajaxToggleWatchFade(this, this.href);
+        return false;
+      })
+      .addClass('watcher-processed');
+  }
+};
 
 
 /********************************************************************
@@ -35,17 +37,17 @@ Drupal.behaviors.watcher = function (context) {
 function ajaxToggleEmailNotifications(el, url) {
   toggleEmailIconStatusAni(el, false);
   $.ajax({
-  	url: url,
-	type: 'GET',
-	data: { async : 'true' },
-	dataType: 'json',
-	timeout: 4000, //set very high to prevent time outs for users with high latency connections
-	success: function (json) {
-	  toggleNotificationStatus(el, json);
-	},
-	complete: function (json) {
-	  toggleEmailIconStatusAni(el, true);
-	}
+    url: url,
+    type: 'GET',
+    data: { async : 'true' },
+    dataType: 'json',
+    timeout: 4000, //set very high to prevent time outs for users with high latency connections
+    success: function (json) {
+      toggleNotificationStatus(el, json);
+    },
+    complete: function (json) {
+      toggleEmailIconStatusAni(el, true);
+    }
   });
 }
 
@@ -62,9 +64,9 @@ function toggleNotificationStatus(el, rdata) {
   var string_title_disabled = Drupal.settings.watcher.binder_notif_title_disabled;
 
   if (rdata['status'] == 'enabled') {
-    $(el).empty().append(string_text_enabled).attr('email_status','enabled').attr('title', string_title_enabled);
+    $(el).empty().append(string_text_enabled).attr('email_status', 'enabled').attr('title', string_title_enabled);
   } else {
-	$(el).empty().append(string_text_disabled).attr('email_status','disabled').attr('title', string_title_disabled);
+    $(el).empty().append(string_text_disabled).attr('email_status', 'disabled').attr('title', string_title_disabled);
   }
 }
 
@@ -74,23 +76,23 @@ function toggleNotificationStatus(el, rdata) {
  * @param {Object} el The element to modify
  */
 function toggleEmailIconStatusAni(el, stop) {
-  if(stop) {
+  if (stop) {
     $(el).removeClass('watcher_binder_send_email_status_icon_from_disabled_to_enabled'); 
-	   $(el).removeClass('watcher_binder_send_email_status_icon_from_enabled_to_disabled');
+    $(el).removeClass('watcher_binder_send_email_status_icon_from_enabled_to_disabled');
     if($(el).attr('email_status')=='enabled') {
-	     $(el).addClass('watcher_binder_send_email_status_icon_enabled');
-  	   $(el).removeClass('watcher_binder_send_email_status_icon_disabled');
-	   } else {
-	     $(el).addClass('watcher_binder_send_email_status_icon_disabled');
-   	  $(el).removeClass('watcher_binder_send_email_status_icon_enabled');
-	   }
-    return true;  	
+      $(el).addClass('watcher_binder_send_email_status_icon_enabled');
+      $(el).removeClass('watcher_binder_send_email_status_icon_disabled');
+    } else {
+      $(el).addClass('watcher_binder_send_email_status_icon_disabled');
+      $(el).removeClass('watcher_binder_send_email_status_icon_enabled');
+    }
+    return true;    
   } 
   
-		if($(el).attr('email_status')=='enabled') {
-	   $(el).addClass('watcher_binder_send_email_status_icon_from_enabled_to_disabled');
+  if ($(el).attr('email_status')=='enabled') {
+    $(el).addClass('watcher_binder_send_email_status_icon_from_enabled_to_disabled');
   } else {
-	  $(el).addClass('watcher_binder_send_email_status_icon_from_disabled_to_enabled');  	
+    $(el).addClass('watcher_binder_send_email_status_icon_from_disabled_to_enabled');   
   }
 }
 
@@ -106,8 +108,8 @@ function toggleEmailIconStatusAni(el, stop) {
  */
 function ajaxToggleWatchFade(el, url) {
   // Fade out the element
-  $(el).fadeTo(400, 0.01, function(){
-  	ajaxToggleWatch(el, url)
+  $(el).fadeTo(400, 0.01, function() {
+    ajaxToggleWatch(el, url)
   });
 }
 
@@ -118,14 +120,15 @@ function ajaxToggleWatchFade(el, url) {
  */
 function ajaxToggleWatch(el, url) {
   $.ajax({
-  	url: url,
-	type: 'GET',
-	data: { async : 'true' },
-	dataType: 'json',
-	timeout: 4000, //set very high to prevent time outs for users with high latency connections
-	success: function (json) {
-	  toggleWatch(el, json);
-	},
+    url: url,
+    type: 'GET',
+    data: { async : 'true' },
+    dataType: 'json',
+    // Set very high to prevent time outs for users with high latency connections
+    timeout: 4000,
+    success: function (json) {
+      toggleWatch(el, json);
+    },
     error: function(json){
       $(el).fadeTo(400, 1);
     }
@@ -143,18 +146,18 @@ function toggleWatch(el, rdata) {
   var string_watched_posts_link = Drupal.settings.watcher.watch_watched_posts_link;
 
   if (rdata['status'] == 'enabled') {
-	$(el).empty().append(string_text_enabled).attr('title', string_title_enabled).addClass('watcher_node_toggle_watching_link_watched');
+  $(el).empty().append(string_text_enabled).attr('title', string_title_enabled).addClass('watcher_node_toggle_watching_link_watched');
     $(el).parent().addClass('watcher_node_watched');
   } 
   else if (rdata['status'] == 'disabled') {
-	$(el).empty().append(string_text_disabled).attr('title', string_title_disabled).removeClass('watcher_node_toggle_watching_link_watched');
+  $(el).empty().append(string_text_disabled).attr('title', string_title_disabled).removeClass('watcher_node_toggle_watching_link_watched');
     $(el).parent().removeClass('watcher_node_watched');
   }
   else {
-	  $(el).parent().fadeOut('fast').replaceWith(rdata['data']).fadeIn('fast');
+    $(el).parent().fadeOut('fast').replaceWith(rdata['data']).fadeIn('fast');
   }
   
-  //Append link to user's list of watched posts if it doesn't already exist
+  // Append link to user's list of watched posts if it doesn't already exist
   var parent = $(el).parent();
   if ($(parent).find('a.watcher_node_help_link_to_binder').length == 0) {
     $(parent).addClass('watcher_node_toggle_watching_link_with_link_to_binder').append(string_watched_posts_link);    
diff --git a/watcher.db.inc b/watcher.db.inc
index a283370..ee82985 100755
--- a/watcher.db.inc
+++ b/watcher.db.inc
@@ -1,5 +1,8 @@
 <?php
 /**
+ * @file
+ * Watcher DB layer
+ * 
  * Watcher Module
  * by Jakob Persson of NodeOne <jakob@nodeone.se>
  * With ideas and feedback from Hans Dekker of Wordsy.com
@@ -35,20 +38,35 @@ define('WATCHER_WATCH_FOR_UPDATES', 3);
  * @return
  *    A paged database result resource
  */
-function _watcher_db_get_watched_nodes_full($user = false, $header = null) {
+function _watcher_db_get_watched_nodes_full($user = FALSE, $header = NULL) {
 // Taken from tracker.module
 // TODO: These queries are very expensive, see http://drupal.org/node/105639
+  $result = FALSE;
   if ($user->uid) {
-    $sql = 'SELECT DISTINCT(n.nid), n.title, n.type, n.changed, n.uid, u.name, wn.send_email, wn.added, GREATEST(n.changed, l.last_comment_timestamp) AS last_updated, l.comment_count FROM {node} n INNER JOIN {node_comment_statistics} l ON n.nid = l.nid INNER JOIN {users} u ON n.uid = u.uid INNER JOIN {watcher_nodes} wn ON n.nid = wn.nid LEFT JOIN {comments} c ON n.nid = c.nid AND (c.status = %d OR c.status IS NULL) WHERE n.status = 1 AND wn.uid = %d';
-    $sql_count = 'SELECT COUNT(DISTINCT(n.nid)) FROM {node} n LEFT JOIN {comments} c ON n.nid = c.nid AND (c.status = %d OR c.status IS NULL) INNER JOIN {watcher_nodes} wn ON n.nid = wn.nid WHERE n.status = 1 AND wn.uid = %d AND wn.uid = %d';
+    $query = db_select('node', 'n')
+      ->extend('PagerDefault')
+      ->distinct()
+      ->fields('n', array('nid', 'title', 'type', 'changed', 'uid'))
+      ->fields('u', array('name'))
+      ->fields('wn', array('send_email', 'added'))
+      ->fields('l', array('comment_count'))
+      ->limit(25);
+    $query->addExpression('GREATEST(n.changed, l.last_comment_timestamp)', 'last_updated');
+    $query->join('node_comment_statistics', 'l', 'n.nid = l.nid');
+    $query->join('users', 'u', 'n.uid = u.uid');
+    $query->join('watcher_nodes', 'wn', 'n.nid = wn.nid');
+    $query->leftJoin('comment', 'c', 'n.nid = c.nid AND (c.status = :cstatus OR c.status IS NULL)', array(':cstatus' => COMMENT_PUBLISHED));
+    $query->condition('n.status', 1);
+    $query->condition('wn.uid', $user->uid);
+    $query->addTag('node_access');
+    
     if ($header) {
-      $sql .= tablesort_sql($header);
+      $query->extend('TableSort')
+        ->orderByHeader($header);
     }
-    $sql = db_rewrite_sql($sql);
-    $sql_count = db_rewrite_sql($sql_count);
-    $result = pager_query($sql, 25, 0, $sql_count, COMMENT_PUBLISHED, $user->uid, $user->uid, $user->uid);
-    return $result;
+    $result = $query->execute();
   }
+  return $result;
 }
 
 /**
@@ -61,13 +79,10 @@ function _watcher_db_get_watched_nodes_full($user = false, $header = null) {
  *    A database result resource
  */
 function _watcher_db_get_watched_nodes_mini($user) {
-  if ($user->uid) {
-    $sql = 'SELECT DISTINCT(nid) FROM {watcher_nodes} WHERE uid = %d';
-  }
-  else {
-    $sql = "SELECT DISTINCT(nid) FROM {watcher_nodes} WHERE mail = '%s'";
-  }
-  $result = db_query($sql, ( $user->uid ? $user->uid : $user->mail ));
+  $sql = $user->uid
+    ? 'SELECT DISTINCT(nid) FROM {watcher_nodes} WHERE uid = :uid_or_mail'
+    : 'SELECT DISTINCT(nid) FROM {watcher_nodes} WHERE mail = :uid_or_mail';
+  $result = db_query($sql, array(':uid_or_mail' => ( $user->uid ? $user->uid : $user->mail )));
   return $result;
 }
 
@@ -81,12 +96,9 @@ function _watcher_db_get_watched_nodes_mini($user) {
  *     A database result set of matching table rows.
  */
 function _watcher_db_get_nids_by_uid($uid) {
-  $sql = 'SELECT nid FROM {watcher_nodes} WHERE uid = %d';
-  $result = db_query($sql, $uid);
-  while($row = db_fetch_object($result)) {
-    return $result;
-  }
-  return false;
+  $sql = 'SELECT nid FROM {watcher_nodes} WHERE uid = :uid';
+  $result = db_query($sql, array(':uid' => $uid));
+  return ( $result->rowCount() ? $result : FALSE );
 }
 
 /**
@@ -99,12 +111,9 @@ function _watcher_db_get_nids_by_uid($uid) {
  *     A database result set of matching table rows.
  */
 function _watcher_db_get_uids_by_nid($nid) {
-  $sql = 'SELECT uid FROM {watcher_nodes} WHERE nid = %d';
-  $result = db_query($sql, $nid);
-  while ($row = db_fetch_object($result)) {
-    return $result;
-  }
-  return false;
+  $sql = 'SELECT uid FROM {watcher_nodes} WHERE nid = :nid';
+  $result = db_query($sql, array(':nid' => $nid));
+  return ( $result->rowCount() ? $result : FALSE );
 }
 
 /**
@@ -118,15 +127,15 @@ function _watcher_db_get_uids_by_nid($nid) {
  */
 function _watcher_db_get_nids_by_user($user) {
   if ($user->uid) {
-    $sql = 'SELECT nid FROM {watcher_nodes} WHERE uid = %d';
-    $result = db_query($sql, $user->uid);
+    $sql = 'SELECT nid FROM {watcher_nodes} WHERE uid = :uid';
+    $result = db_query($sql, array(':uid' => $user->uid));
   }
   else {
-    $sql = "SELECT nid FROM {watcher_nodes} WHERE mail = '%s'";
-    $result = db_query($sql, $user->mail);
+    $sql = 'SELECT nid FROM {watcher_nodes} WHERE mail = :mail';
+    $result = db_query($sql, array(':mail' => $user->mail));
   }
-
-  while ($row = db_fetch_object($result)) {
+  $nids = array();
+  foreach ($result as $row) {
     $nids[$row->nid] = $row->nid;
   }
 
@@ -147,18 +156,14 @@ function _watcher_db_get_nids_by_user($user) {
  */
 function _watcher_db_get_user_nid($user, $nid) {
   if (!$user->uid) {
-    $sql = "SELECT mail FROM {watcher_nodes} WHERE mail = '%s' AND nid = %d";
-    $result = db_query($sql, $user->mail, $nid);
+    $sql = 'SELECT mail FROM {watcher_nodes} WHERE mail = :mail AND nid = :nid';
+    $result = db_query($sql, array(':mail' => $user->mail, ':nid' => $nid));
   }
   else {
-  $sql = 'SELECT uid FROM {watcher_nodes} WHERE uid = %d AND nid = %d';
-    $result = db_query($sql, $user->uid, $nid);
-  }
-
-  while($row = db_fetch_object($result)) {
-    return $result;
+    $sql = 'SELECT uid FROM {watcher_nodes} WHERE uid = :uid AND nid = :nid';
+    $result = db_query($sql, array(':uid' => $user->uid, ':nid' => $nid));
   }
-  return false;
+  return ( $result->rowCount() ? $result : FALSE );
 }
 
 /**
@@ -172,29 +177,55 @@ function _watcher_db_get_user_nid($user, $nid) {
  *     A string indicating what an anonymous user watches for: all, comments, updates
  *
  * @return
- *     Boolean true on success
+ *     Boolean TRUE on success
  */
-function _watcher_db_set_nid_user($nid, $user, $what = null) {
+function _watcher_db_set_nid_user($nid, $user, $what = NULL) {
 
   if (!$user->uid) {
     // If the user is anonymous, we first remove any already existing rows and replace
     // them to allow the user to alter previously set watches
-    $sql = "DELETE FROM {watcher_nodes} WHERE nid = %d AND uid = %d AND mail = '%s'";
-    db_query($sql, $nid, $user->uid, $user->mail);
+    db_delete('watcher_nodes')
+      ->condition('nid', $nid)
+      ->condition('uid', $uid)
+      ->condition('mail', $mail)
+      ->execute();
   }
 
+  $res = TRUE;
   if ($what) {
     // Mapping integers to strings
     $for['all'] = WATCHER_WATCH_FOR_ALL;
     $for['comments'] = WATCHER_WATCH_FOR_COMMENTS;
     $for['updates'] = WATCHER_WATCH_FOR_UPDATES;
 
-    $sql = "INSERT INTO {watcher_nodes} (uid, mail, nid, added, watch_for) VALUES(%d, '%s', %d, %d, %d)";
-    $res = db_query($sql, $user->uid, $user->mail, $nid, time(), $for[$what]);
+    try {
+      db_insert('watcher_nodes')
+        ->fields(array(
+          'uid' => $user->uid,
+          'mail' => $user->mail,
+          'nid' => $nid,
+          'added' => REQUEST_TIME,
+          'watch_for' => $for[$what],
+        ))
+        ->execute();
+    }
+    catch (Exception $e) {
+      $res = FALSE;
+    }
   }
   else {
-    $sql = "INSERT INTO {watcher_nodes} (uid, nid, added) VALUES(%d, %d, %d)";
-    $res = db_query($sql, $user->uid, $nid, time());
+    try {
+      db_insert('watcher_nodes')
+        ->fields(array(
+          'uid' => $user->uid,
+          'nid' => $nid,
+          'added' => REQUEST_TIME,
+        ))
+        ->execute();
+    }
+    catch (Exception $e) {
+      $res = FALSE;
+    }
   }
 
   return $res;
@@ -212,18 +243,21 @@ function _watcher_db_set_nid_user($nid, $user, $what = null) {
  */
 function _watcher_db_delete_nids_user($nids, $user) {
   if (!count($nids)) {
-    return;
+    return FALSE;
   }
-  $sql_in = implode(',', $nids);
   if (!$user->uid) {
-    $sql = "DELETE FROM {watcher_nodes} WHERE mail = '%s' AND nid IN(%s)";
-    $res = db_query($sql, $user->mail, $sql_in);
+    $res = db_delete('watcher_nodes')
+      ->condition('mail', $user->mail)
+      ->condition('nid', $nids, 'IN')
+      ->execute();
   }
   else {
-    $sql = 'DELETE FROM {watcher_nodes} WHERE uid = %d AND nid IN(%s)';
-    $res = db_query($sql, $user->uid, $sql_in);
+    $res = db_delete('watcher_nodes')
+      ->condition('uid', $user->uid)
+      ->condition('nid', $nids, 'IN')
+      ->execute();
   }
-  return (bool) db_affected_rows();
+  return (bool) $res;
 }
 
 /**
@@ -234,8 +268,9 @@ function _watcher_db_delete_nids_user($nids, $user) {
  *    Boolean of success or failure
  */
 function _watcher_db_delete_nid($nid) {
-  $sql = 'DELETE FROM {watcher_nodes} WHERE nid = %d';
-  $res = db_query($sql, $nid);
+  $res = db_delete('watcher_nodes')
+    ->condition('nid', $nid)
+    ->execute();
   return (bool) $res;
 }
 
@@ -247,8 +282,9 @@ function _watcher_db_delete_nid($nid) {
  *     A boolean indicating success/failur
  */
 function _watcher_db_delete_uid($uid) {
-  $sql = 'DELETE FROM {watcher_nodes} WHERE uid = %d';
-  $res = db_query($sql, $uid);
+  $res = db_delete('watcher_nodes')
+    ->condition('uid', $uid)
+    ->execute();
   return (bool) $res;
 }
 
@@ -263,11 +299,10 @@ function _watcher_db_delete_uid($uid) {
  *     Boolean True if email notifications are enabled for this user and node
  */
 function _watcher_db_get_send_email_status($nid, $uid) {
-  $sql = 'SELECT send_email FROM {watcher_nodes} WHERE uid = %d AND nid = %d';
-  $result = db_query($sql, $uid, $nid);
-  $row = db_fetch_object($result);
-  if ($row->send_email) return true;
-  return false;
+  $sql = 'SELECT send_email FROM {watcher_nodes} WHERE uid = :uid AND nid = :nid';
+  $result = db_query($sql, array(':uid' => $uid, ':nid' => $nid));
+  $row = $result->fetchObject();
+  return ($row->send_email ? TRUE : FALSE);
 }
 
 /**
@@ -283,15 +318,36 @@ function _watcher_db_get_send_email_status($nid, $uid) {
  *     Boolean denoting success/failure.
  */
 function _watcher_db_set_send_email_status($nid, $user, $send_email = 0) {
+  $res = TRUE;
   if ($user->uid) {
-    $sql = 'UPDATE {watcher_nodes} SET send_email = %d WHERE uid = %d AND nid = %d';
-    $res = db_query($sql, $send_email, $user->uid, $nid);
+    try {
+      db_update('watcher_nodes')
+        ->fields(array(
+          'send_email' => $send_email,
+        ))
+        ->condition('uid', $user->uid)
+        ->condition('nid', $nid)
+        ->execute();
+    }
+    catch (Exception $e) {
+      $res = FALSE;
+    }
   }
   else {
-    $sql = "UPDATE {watcher_nodes} SET send_email = %d WHERE mail = '%s' AND nid = %d";
-    $res = db_query($sql, $send_email, $user->mail, $nid);
+    try {
+      db_update('watcher_nodes')
+        ->fields(array(
+          'send_email' => $send_email,
+        ))
+        ->condition('mail', $user->mail)
+        ->condition('nid', $nid)
+        ->execute();
+    }
+    catch (Exception $e) {
+      $res = FALSE;
+    }
   }
-  return ((bool) $res);
+  return $res;
 }
 
 /**
@@ -302,25 +358,30 @@ function _watcher_db_set_send_email_status($nid, $user, $send_email = 0) {
  * @param $settings
  *     An associative array of user settings
  * @return
- *     Boolean true on success
+ *     Boolean TRUE on success
  */
 function _watcher_db_set_user_settings($uid, $settings) {
 
   //Add custom field to mark these user settings as custom
   $settings['custom'] = 1;
 
-  //Serialize settings
-  $fields = implode(', ', array_keys($settings));
-  $values = implode(', ', array_values($settings));
-
   // First delete existing settings
-  $sql = 'DELETE FROM {watcher_user_settings} WHERE uid = %d';
-  db_query($sql, $uid);
+  db_delete('watcher_user_settings')
+    ->condition('uid', $uid)
+    ->execute();
 
   // Insert new settings
-  $sql = 'INSERT INTO {watcher_user_settings} (uid, %s) VALUES (%d, %s)';
-  $res = db_query($sql, $fields, $uid, $values);
-  return (bool) $res;
+  $settings['uid'] = $uid;
+  $res = TRUE;
+  try {
+    db_insert('watcher_user_settings')
+      ->fields($settings)
+      ->execute();
+  }
+  catch (Exception $e) {
+    $res = FALSE;
+  }
+  return $res;
 }
 
 /**
@@ -332,9 +393,16 @@ function _watcher_db_set_user_settings($uid, $settings) {
  *     Boolean True on success
  */
 function _watcher_db_delete_user_settings($uid) {
-  $sql = 'DELETE FROM {watcher_user_settings} WHERE uid = %d';
-  $res = db_query($sql, $uid);
-  return (bool) $res;
+  $res = TRUE;
+  try {
+    db_delete('watcher_user_settings')
+      ->condition('uid', $uid)
+      ->execute();
+  }
+  catch (Exception $e) {
+    $res = FALSE;
+  }
+  return $res;
 }
 
 /**
@@ -349,14 +417,15 @@ function _watcher_db_get_user_settings($uid) {
   // Cache settings
   static $settings;
   if (!isset($settings)) {
-    $sql = 'SELECT * FROM {watcher_user_settings} WHERE uid = %d';
-    $result = db_query($sql, $uid);
-    while($row = db_fetch_array($result)) {
-      unset($row['uid']);
-      $settings = $row;
-      return $settings;
+    $sql = 'SELECT * FROM {watcher_user_settings} WHERE uid = :uid';
+    $result = db_query($sql, array(':uid' => $uid));
+    if ($result->rowCount()) {
+      $settings = $result->fetchObject();
+      unset($settings->uid);
+    }
+    else {
+      $settings = FALSE;
     }
-    $settings = false;
   }
   return $settings;
 }
@@ -367,26 +436,38 @@ function _watcher_db_get_user_settings($uid) {
  * @param $settings
  *    An associative array of settings
  * @return
- *    A boolean true on success
+ *    A boolean TRUE on success
  */
 function _watcher_db_user_settings_update_defaults($settings) {
   // Users may have registered and not had settings set yet so add rows for any users that are "missing"
-  $sql = 'INSERT INTO {watcher_user_settings} (uid) SELECT u.uid FROM {users} u LEFT JOIN {watcher_user_settings} wus ON u.uid = wus.uid WHERE ISNULL(custom)';
-  $res = db_query($sql);
+  $query = db_select('users', 'u');
+  $query->leftJoin('watcher_user_settings', 'wus', 'u.uid = wus.uid');
+  $query->addField('u', 'uid');
+  $query->isNull('custom');
+  $res = TRUE;
+  try {
+    db_insert('watcher_user_settings')
+      ->from($query)
+      ->execute();
+  }
+  catch (Exception $e) {
+    $res = FALSE;
+  }
 
   // If defaults are set, apply them, otherwise return
   if (is_array($settings)) {
-    // Format settings array as string
-    foreach ($settings as $setting => $value) {
-      $insert_array[] = $setting .'='. $value;
-    }
-    $insert_string = implode(', ', $insert_array);
-
     // Update all users who haven't customized their settings yet
-    $sql = 'UPDATE {watcher_user_settings} SET %s WHERE custom <> 1';
-    $res = db_query($sql, $insert_string);
+    try {
+      db_update('watcher_user_settings')
+        ->fields($settings)
+        ->condition('custom', '1', '<>')
+        ->execute();
+    }
+    catch (Exception $e) {
+      $res = FALSE;
+    }
   }
-  return (bool) $res;
+  return $res;
 }
 
 /**
@@ -395,15 +476,12 @@ function _watcher_db_user_settings_update_defaults($settings) {
  * @param $uid
  *    A user UID
  * @return
- *    A boolean true if given UID has customized his/her user settings
+ *    A boolean TRUE if given UID has customized his/her user settings
  */
 function _watcher_db_user_settings_uid_custom($uid) {
-  $sql = 'SELECT custom FROM {watcher_user_settings} WHERE uid = %d AND custom = 1';
-  $res = db_query($sql, $uid);
-  while($row = db_fetch_object($res)) {
-    return true;
-  }
-  return false;
+  $sql = 'SELECT custom FROM {watcher_user_settings} WHERE uid = :uid AND custom = 1';
+  $result = db_query($sql, array(':uid' => $uid));
+  return ( (bool) $result->rowCount() );
 }
 
 /**
@@ -417,10 +495,10 @@ function _watcher_db_user_settings_uid_custom($uid) {
  *     An array of objects with uid as key representing users, with attributes uid, mail and name
  */
 function _watcher_db_get_users_notify_node_update($nid, $uid_exclude) {
-  $sql = "SELECT wn.uid, wn.mail wnmail, u.mail umail, u.name FROM {watcher_nodes} wn LEFT JOIN {watcher_user_settings} wus ON wus.uid = wn.uid LEFT JOIN {users} u ON u.uid = wus.uid WHERE nid = %d AND ((wn.uid <> 0 AND wn.uid <> %d AND notifications_updates = 1 AND send_email = 1) OR (wn.uid = 0 AND (watch_for = 1 OR watch_for = 3)))";
-  $res = db_query($sql, $nid, $uid_exclude);
+  $sql = "SELECT wn.uid, wn.mail wnmail, u.mail umail, u.name FROM {watcher_nodes} wn LEFT JOIN {watcher_user_settings} wus ON wus.uid = wn.uid LEFT JOIN {users} u ON u.uid = wus.uid WHERE nid = :nid AND ((wn.uid <> 0 AND wn.uid <> :uid_exclude AND notifications_updates = 1 AND send_email = 1) OR (wn.uid = 0 AND (watch_for = 1 OR watch_for = 3)))";
+  $res = db_query($sql, array(':nid' => $nid, ':uid_exclude' => $uid_exclude));
   $users = array();
-  while ($row = db_fetch_object($res)) {
+  foreach ($res as $row) {
     $users[$row->uid] = $row;
   }
   return $users;
@@ -439,13 +517,9 @@ function _watcher_db_get_users_notify_node_update($nid, $uid_exclude) {
  *     An array of objects with uid as key representing users, with attributes uid, mail and name
  */
 function _watcher_db_get_users_notify_comment_insert($nid, $uid_exclude) {
-  $sql = 'SELECT wn.uid, wn.mail wnmail, u.mail umail, u.name FROM {watcher_nodes} wn LEFT JOIN {watcher_user_settings} wus ON wus.uid = wn.uid LEFT JOIN {users} u ON u.uid = wus.uid WHERE nid = %d AND ((wn.uid <> 0 AND wn.uid <> %d AND notifications_new_comments = 1 AND send_email = 1) OR (wn.uid = 0 AND (watch_for = 1 OR watch_for = 2)))';
-  $res = db_query($sql, $nid, $uid_exclude);
-  $users = array();
-  while ($row = db_fetch_object($res)) {
-    $users[] = $row;
-  }
-  return $users;
+  $sql = 'SELECT wn.uid, wn.mail wnmail, u.mail umail, u.name FROM {watcher_nodes} wn LEFT JOIN {watcher_user_settings} wus ON wus.uid = wn.uid LEFT JOIN {users} u ON u.uid = wus.uid WHERE nid = :nid AND ((wn.uid <> 0 AND wn.uid <> :uid_exclude AND notifications_new_comments = 1 AND send_email = 1) OR (wn.uid = 0 AND (watch_for = 1 OR watch_for = 2)))';
+  $res = db_query($sql, array(':nid' => $nid, ':uid_exclude' => $uid_exclude));
+  return $res->fetchAll();
 }
 
 /**
@@ -461,10 +535,10 @@ function _watcher_db_get_users_notify_comment_insert($nid, $uid_exclude) {
  *      An array of objects with uid as key representing users, with attributes uid, mail and name
  */
 function _watcher_db_get_users_notify_about_node($nid, $uid_exclude) {
-  $sql = 'SELECT wn.uid, wn.mail wnmail, u.mail umail, u.name FROM {watcher_nodes} wn LEFT JOIN {users} u ON u.uid = wn.uid WHERE nid = %d AND ((wn.uid <> 0 AND wn.uid <> %d AND send_email = 1) OR (NOT ISNULL(watch_for)))';
-  $res = db_query($sql, $nid, $uid_exclude);
+  $sql = 'SELECT wn.uid, wn.mail wnmail, u.mail umail, u.name FROM {watcher_nodes} wn LEFT JOIN {users} u ON u.uid = wn.uid WHERE nid = :nid AND ((wn.uid <> 0 AND wn.uid <> :uid_exclude AND send_email = 1) OR (NOT ISNULL(watch_for)))';
+  $res = db_query($sql, array(':nid' => $nid, ':uid_exclude' => $uid_exclude));
   $users = array();
-  while ($row = db_fetch_object($res)) {
+  foreach ($res as $row) {
     $users[$row->uid] = $row;
   }
   return $users;
@@ -487,20 +561,31 @@ function _watcher_db_get_users_notify_about_node($nid, $uid_exclude) {
  *     A database result resource
  */
 function _watcher_db_insert_users_notification_queue($r_uid, $r_email, $subject, $message) {
-  $sql = "INSERT INTO {watcher_notify_queue} (uid, mail, subject, message) VALUES (%d, '%s', '%s', '%s')";
-  $res = db_query($sql, $r_uid, $r_email, $subject, $message);
-  return (bool) $res;
+  $res = TRUE;
+  try {
+    db_insert('watcher_notify_queue')
+      ->fields(array(
+        'uid' => $r_uid,
+        'mail' => $r_email,
+        'subject' => $subject,
+        'message' => $message,
+      ))
+      ->execute();
+  }
+  catch (Exception $e) {
+    $res = FALSE;
+  }
+  return $res;
 }
 
 /**
  * Delete all rows in notification queue table
  *
  * @return
- *    A boolean denoting whether any rows were deleted, false if none, true if one or more
+ *    A boolean denoting whether any rows were deleted, FALSE if none, TRUE if one or more
  */
 function _watcher_db_delete_users_notification_queue_all() {
-  $sql = "DELETE FROM {watcher_notify_queue}";
-  $res = db_query($sql);
+  $res = db_delete('watcher_notify_queue')->execute();
   return (bool) $res;
 }
 
@@ -508,11 +593,10 @@ function _watcher_db_delete_users_notification_queue_all() {
  * Get messages from the notification queue table
  */
 function _watcher_db_get_users_notification_queue() {
-  $sql = "SELECT * FROM {watcher_notify_queue}";
-  $res = db_query($sql);
-  while ($qmsg = db_fetch_object($res)) {
-    $qmsgs[] = $qmsg;
-  }
+  $qmsgs = db_select('watcher_notify_queue')
+    ->fields('watcher_notify_queue')
+    ->execute()
+    ->fetchAll();
   return $qmsgs;
 }
 
@@ -531,9 +615,9 @@ function _watcher_db_delete_users_notification_queue($qids) {
   $offset = 0;
   for ($i = 1; $offset < count($qids); $i++) {
     $batch = array_slice($qids, $offset, $limit);
-    $in = implode(',', $batch);
-    $sql = "DELETE FROM {watcher_notify_queue} WHERE qid IN (%s)";
-    db_query($sql, $in);
+    db_delete('watcher_notify_queue')
+      ->condition('qid', $batch, 'IN')
+      ->execute();
     $offset = (($i * $limit) - 1);
   }
 }
@@ -551,11 +635,11 @@ function _watcher_db_stats_notification_queue() {
 
   // Obtain number of rows
   $res = db_query($sql3);
-  $stat['num_rows'] = db_result($res);
+  $stat['num_rows'] = $res->fetchField();
 
   // Obtain the contents of the queue table
   $res = db_query($sql);
-  while ($row = db_fetch_object($res)) {
+  foreach ($res as $row) {
 
     // Load fields
     $data['qid'] = $row->qid;
@@ -574,13 +658,10 @@ function _watcher_db_stats_notification_queue() {
   // Obtain the number of notifications sent - this is not 100% accurate since we cannot
   // entirely trust the increment counter
   $res2 = db_query($sql2);
-  $num_sent = db_result($res2);
-  $stat['num_sent'] = ( $num_sent = db_result($res2) ? $num_sent : 0 );
+  $num_sent = $res2->fetchField();
+  $stat['num_sent'] = ( $num_sent = $res2->fetchField() ? $num_sent : 0 );
 
-  if ($res) {
-    return $stat;
-  }
-  return false;
+  return $res ? $stat : FALSE;
 }
 
 /**
@@ -596,14 +677,12 @@ function _watcher_db_stats_watched_nodes_users() {
 
   // Obtain number of rows
   $res = db_query($sql);
-  $stat['num_users_reg'] = db_result($res);
+  $stat['num_users_reg'] = $res->fetchField();
 
   $res2 = db_query($sql2);
-  $stat['num_users_anon'] = db_result($res2);
+  $stat['num_users_anon'] = $res2->fetchField();
 
-
-  if ($res && $res2) return $stat;
-  return false;
+  return ($res && $res2) ? $stat : FALSE;
 }
 
 /**
@@ -622,37 +701,30 @@ function _watcher_db_stats_user_settings() {
 
   // Obtain number of users with settings
   $res = db_query($sql);
-  $stat['num_users_with_settings'] = db_result($res);
+  $stat['num_users_with_settings'] = $res->fetchField();
 
   // Obtain number of users without setting
   $res2 = db_query($sql2);
-  $stat['num_users'] = db_result($res2);
+  $stat['num_users'] = $res2->fetchField();
   $stat['num_users_no_settings'] = $stat['num_users'] - $stat['num_users_with_settings'];
 
-  if ($res) return $stat;
-  return false;
+  return $res ? $stat : FALSE;
 }
 
 /**
  * Return the newest node
  */
 function _watcher_db_get_newest_node() {
-  $sql = 'SELECT nid FROM {node} ORDER BY created DESC LIMIT 0,1';
-  $res = db_query($sql);
-  if ($nid = db_result($res)) {
-    return $nid;
-  }
-  return false;
+  $sql = 'SELECT MAX(nid) nid FROM {node}';
+  $nid = db_query($sql)->fetchField();
+  return $nid ? $nid : FALSE;
 }
 
 /**
  * Return the newest comment
  */
 function _watcher_db_get_newest_comment() {
-  $sql = 'SELECT cid FROM {comments} ORDER BY timestamp DESC LIMIT 0,1';
-  $res = db_query($sql);
-  if ($cid = db_result($res)) {
-    return $cid;
-  }
-  return false;
+  $sql = 'SELECT MAX(cid) cid FROM {comment}';
+  $cid = db_query($sql)->fetchField();
+  return $cid ? $cid : FALSE;
 }
diff --git a/watcher.info b/watcher.info
index bbeb681..7f8d21a 100644
--- a/watcher.info
+++ b/watcher.info
@@ -1,7 +1,7 @@
 name = "Watcher"
 description = "Watcher enables your site's users to watch nodes for changes and new comments and be notified about them."
 package = Other
-core = 6.x
+core = 7.x
 dependencies[] = node
 dependencies[] = token
 dependencies[] = comment
\ No newline at end of file
diff --git a/watcher.install b/watcher.install
index d9f3923..9f051d6 100644
--- a/watcher.install
+++ b/watcher.install
@@ -16,35 +16,27 @@
  */
 
 /**
- * Implementation of hook_install()
+ * Implements hook_install()
  */
 function watcher_install() {
-  if (db_table_exists('watcher_nodes') && db_table_exists('watcher_notify_queue') && db_table_exists('watcher_user_settings')) {
-    drupal_set_message("Watcher's tables already exist in the database, this indicates Watcher has been installed previously. You can probably go ahead and use Watcher without any further actions.");
-    return;
-  }
-
-  if (drupal_install_schema('watcher')) {
-    drupal_set_message('Watcher was successfully installed.');
-  }
 }
 
 /**
- * Implementation of hook_uninstall()
+ * Implements hook_uninstall()
  */
 function watcher_uninstall() {
 
-  // Uninstall schemas
-  drupal_uninstall_schema('watcher');
-
   // Empty site cache
-  cache_clear_all('*', 'cache', true);
-  cache_clear_all('*', 'cache_filter', true);
-  cache_clear_all('*', 'cache_menu', true);
-  cache_clear_all('*', 'cache_page', true);
+  cache_clear_all('*', 'cache', TRUE);
+  cache_clear_all('*', 'cache_filter', TRUE);
+  cache_clear_all('*', 'cache_menu', TRUE);
+  cache_clear_all('*', 'cache_page', TRUE);
 
   // Clear variables
-  db_query("DELETE FROM {variable} WHERE name LIKE('%s%%') ", 'watcher_');
+  db_delete('variable')
+    ->condition('name', 'watcher_%', 'LIKE')
+    ->execute();
+
   cache_clear_all('variables', 'cache');
 
 }
@@ -53,21 +45,20 @@ function watcher_uninstall() {
  * Updates 5.x -> 6.x-1.0
  */
 function watcher_update_6000() {
-  $ret = array();
-  db_add_field($ret, 'watcher_nodes', 'mail', array('type' => 'varchar', 'length' => 128, 'default' => null));
-  db_drop_primary_key($ret, 'watcher_nodes');
-  db_add_primary_key($ret, 'watcher_nodes', array('uid', 'nid', 'mail'));
-  return $ret;
+  db_add_field('watcher_nodes', 'mail', array('type' => 'varchar', 'length' => 128, 'default' => NULL));
+  db_drop_primary_key('watcher_nodes');
+  db_add_primary_key('watcher_nodes', array('uid', 'nid', 'mail'));
+  return t('Watcher has been successfully updated to version 6.x-1.0.');
+  throw new DrupalUpdateException('Watcher update to 6.x-1.0 failed.');
 }
 
 function watcher_update_6001() {
-  $ret = array();
-  db_add_field($ret, 'watcher_nodes', 'watch_for', array('type' => 'int', 'size' => 'tiny', 'default' => null));
-  return $ret;
+  db_add_field('watcher_nodes', 'watch_for', array('type' => 'int', 'size' => 'tiny', 'default' => NULL));
+  return t('Watcher has been successfully updated to version 6.x-1.1.');
+  throw new DrupalUpdateException('Watcher update to 6.x-1.1 failed.');
 }
 
 function watcher_update_6002() {
-  $ret = array();
   $schema = watcher_schema();
   foreach ($schema as $table => $table_definition) {
     if ($table == 'watcher_user_settings') {
@@ -87,12 +78,12 @@ function watcher_update_6002() {
     }
   }
   
-  return $ret;
+  return t('Watcher has been successfully updated to version 6.x-1.2.');
+  throw new DrupalUpdateException('Watcher update to 6.x-1.2 failed.');
 }
 
-
 /**
- * Implementation of hook_schema()
+ * Implements hook_schema()
  */
 function watcher_schema() {
   $schema['watcher_nodes'] = array(
@@ -101,40 +92,40 @@ function watcher_schema() {
       'uid' => array(
         'description' => 'Holds UID of user',
         'type' => 'int',
-        'not null' => true,
+        'not NULL' => TRUE,
         'disp-width' => '10'
       ),
       'nid' => array(
         'description' => 'Holds NID of node',
         'type' => 'int',
-        'not null' => true,
+        'not NULL' => TRUE,
         'disp-width' => '10'
       ),
       'mail' => array(
         'description' => 'Holds email address of user (if user is anonymous)',
         'type' => 'varchar',
         'length' => 128,
-        'default' => null
+        'default' => NULL
       ),
       'send_email' => array(
         'description' => 'Whether the user wants to be notified by email or not',
         'type' => 'int',
         'size' => 'tiny',
-        'not null' => true,
+        'not NULL' => TRUE,
         'default' => 0,
         'disp-width' => '1'
       ),
       'added' => array(
         'description' => 'Timestamp of when row was added',
         'type' => 'int',
-        'not null' => true,
+        'not NULL' => TRUE,
         'disp-width' => '11'
       ),
       'watch_for' => array(
         'description' => 'What the user is watching for (anonymous users): 1 = all, 2 = comments, 3 = updates',
         'type' => 'int',
         'size' => 'tiny',
-        'default' => null
+        'default' => NULL
       ),
     ),
     'primary key' => array('uid', 'nid', 'mail'),
@@ -146,31 +137,31 @@ function watcher_schema() {
       'qid' => array(
         'description' => 'Queue item ID',
         'type' => 'serial',
-        'not null' => true,
+        'not NULL' => TRUE,
         'disp-width' => '32'
       ),
       'uid' => array(
         'description' => 'Recipient UID',
         'type' => 'int',
-        'not null' => true,
+        'not NULL' => TRUE,
         'disp-width' => '10'
       ),
       'mail' => array(
         'description' => 'Recipient email address',
         'type' => 'varchar',
         'length' => '64',
-        'not null' => true
+        'not NULL' => TRUE
       ),
       'subject' => array(
         'description' => 'Message subject',
         'type' => 'varchar',
         'length' => '192',
-        'not null' => true
+        'not NULL' => TRUE
       ),
       'message' => array(
         'description' => 'Notification message',
         'type' => 'text',
-        'not null' => true
+        'not NULL' => TRUE
       )
     ),
     'primary key' => array('qid'),
@@ -182,14 +173,14 @@ function watcher_schema() {
       'uid' => array(
         'description' => 'User UID',
         'type' => 'int',
-        'not null' => true,
+        'not NULL' => TRUE,
         'disp-width' => '10',
       ),
       'automatic_enable_notifications' => array(
         'description' => 'Automatically enable notifications for the post when a user starts watching a post',
         'type' => 'int',
         'size' => 'tiny',
-        'not null' => true,
+        'not NULL' => TRUE,
         'disp-width' => '1',
         'default' => 0
       ),
@@ -197,7 +188,7 @@ function watcher_schema() {
         'description' => 'User will be notified about updates of posts the user watches',
         'type' => 'int',
         'size' => 'tiny',
-        'not null' => true,
+        'not NULL' => TRUE,
         'disp-width' => '1',
         'default' => 0
       ),
@@ -205,7 +196,7 @@ function watcher_schema() {
         'description' => 'User will be notified about new comments on posts the user watches',
         'type' => 'int',
         'size' => 'tiny',
-        'not null' => true,
+        'not NULL' => TRUE,
         'disp-width' => '1',
         'default' => 0
       ),
@@ -213,7 +204,7 @@ function watcher_schema() {
         'description' => 'User will automatically watch nodes the user comments on',
         'type' => 'int',
         'size' => 'tiny',
-        'not null' => true,
+        'not NULL' => TRUE,
         'disp-width' => '1',
         'default' => 0
       ),
@@ -221,7 +212,7 @@ function watcher_schema() {
         'description' => 'User will automatically watch nodes the user creates',
         'type' => 'int',
         'size' => 'tiny',
-        'not null' => true,
+        'not NULL' => TRUE,
         'disp-width' => '1',
         'default' => 0
       ),
@@ -229,7 +220,7 @@ function watcher_schema() {
         'description' => 'Whether the user\'s list of watched posts should be viewable by others',
         'type' => 'int',
         'size' => 'tiny',
-        'not null' => true,
+        'not NULL' => TRUE,
         'disp-width' => '1',
         'default' => 0
       ),
@@ -237,7 +228,7 @@ function watcher_schema() {
         'description' => 'Whether the user has customized the settings or whether they were derived from the defaults',
         'type' => 'int',
         'size' => 'tiny',
-        'not null' => true,
+        'not NULL' => TRUE,
         'disp-width' => '1',
         'default' => 0
       )
diff --git a/watcher.module b/watcher.module
index dea9465..5bbaf0a 100644
--- a/watcher.module
+++ b/watcher.module
@@ -20,6 +20,24 @@
  ***************************************************************************************/
 
 /**
+ * Return a themed box.
+ * The function is the duplicate of original theme_box() from Drupal 6
+ *
+ * @param $title
+ *   The subject of the box.
+ * @param $content
+ *   The content of the box.
+ * @param $region
+ *   The region in which the box is displayed.
+ * @return
+ *   A string containing the box output.
+ */
+function theme_watcher_box($variables = array()) {
+  $output = '<h2 class="title">'. $variables['title'] .'</h2><div>'. $variables['content'] .'</div>';
+  return $output;
+}
+
+/**
  * Return a themed personal binder page
  *
  * @param $intro_text
@@ -32,21 +50,21 @@
  * @return
  *    A themed personal binder page
  */
-function theme_watcher_binder($intro_text = null, $posts_table_header, $posts_table_body) {
+function theme_watcher_binder($variables = array()) {
   $output  = '<div id="watcher_binder">';
 
   // Intro text
-  if ($intro_text) {
+  if ($variables['intro_text']) {
     $output .= '  <div id="watcher_binder_intro">';
-    $output .= theme('box', null, $intro_text);
+    $output .= theme('watcher_box', array('content' => $variables['intro_text']));
     $output .= '  </div>';
   }
 
   // Table
-  $output .= theme('table', $posts_table_header, $posts_table_body);
+  $output .= theme('table', array('header' => $variables['posts_table_header'], 'rows' => $variables['posts_table_body']));
 
   // Pager
-  $output .= theme('pager', NULL, 25, 0);
+  $output .= theme('pager');
 
   $output .= '</div>';
 
@@ -73,16 +91,16 @@ function theme_watcher_binder($intro_text = null, $posts_table_header, $posts_ta
  * @return
  *    A themed icon for toggling email notifications
  */
-function theme_watcher_binder_email_icon($t, $type, $url, $query = null) {
+function theme_watcher_binder_email_icon($variables) {
   $output = l(
-  ( $type == 'enabled' ? $t['binder_notif_text_enabled'] : $t['binder_notif_text_disabled'] ),
-  $url,
+  ( $variables['type'] == 'enabled' ? $variables['t']['binder_notif_text_enabled'] : $variables['t']['binder_notif_text_disabled'] ),
+  $variables['url'],
   array(
-      'query' => $query,
+      'query' => $variables['query'],
       'attributes' => array(
-        'class' => "watcher_binder_send_email_status_icon watcher_binder_send_email_status_icon_$type",
-        'title' => ( $type == 'enabled' ? $t['binder_notif_title_enabled'] : $t['binder_notif_title_disabled'] ),
-        'email_status' => $type,
+        'class' => "watcher_binder_send_email_status_icon watcher_binder_send_email_status_icon_{$variables['type']}",
+        'title' => ( $variables['type'] == 'enabled' ? $variables['t']['binder_notif_title_enabled'] : $variables['t']['binder_notif_title_disabled'] ),
+        'email_status' => $variables['type'],
   ))
   );
   return $output;
@@ -99,12 +117,12 @@ function theme_watcher_binder_email_icon($t, $type, $url, $query = null) {
  * @return
  *    A themed link for stopping watching a node
  */
-function theme_watcher_binder_stop_watching_icon($url, $query = null) {
+function theme_watcher_binder_stop_watching_icon($variables) {
   $output = l(
   t('Stop watching'),
-  $url,
+  $variables['url'],
   array(
-      'query' => $query,
+      'query' => $variables['query'],
       'attributes' => array(
         'class' => "watcher_binder_stop_watching_icon",
         'title' => t('Stop watching this post.'),
@@ -135,8 +153,8 @@ function theme_watcher_binder_stop_watching_icon($url, $query = null) {
  *    A themed widget for toggling watching of the given nid
  *
  */
-function theme_watcher_node_toggle_watching_link($uid, $nid, $query, $user_is_watching, $t = array()) {
-
+function theme_watcher_node_toggle_watching_link($variables) {
+  $user_is_watching = $variables['user_is_watching'];
   // Set up classes
   $class_watch_status_link = ( $user_is_watching ? ' watcher_node_toggle_watching_link_watched' : '');
   $class_watch_status_container = ( $user_is_watching ? ' watcher_node_watched' : '');
@@ -145,13 +163,13 @@ function theme_watcher_node_toggle_watching_link($uid, $nid, $query, $user_is_wa
 
   // Output a link
   $output .= l(
-  ( $user_is_watching ? $t['watch_toggle_enabled'] : $t['watch_toggle_disabled'] ),
-    "user/$uid/watcher/toggle/$nid",
+  ( $user_is_watching ? $variables['t']['watch_toggle_enabled'] : $variables['t']['watch_toggle_disabled'] ),
+    "user/{$variables['uid']}/watcher/toggle/{$variables['nid']}",
   array(
-      'query' => $query,
+      'query' => $variables['query'],
       'attributes' => array(
         'class' => "watcher_node_toggle_watching_link$class_watch_status_link",
-        'title' => ( $user_is_watching ? $t['watch_toggle_enabled_title'] : $t['watch_toggle_disabled_title'] ),
+        'title' => ( $user_is_watching ? $variables['t']['watch_toggle_enabled_title'] : $variables['t']['watch_toggle_disabled_title'] ),
   ))
   );
 
@@ -170,9 +188,9 @@ function theme_watcher_node_toggle_watching_link($uid, $nid, $query, $user_is_wa
  *    A themed help page
  *
  */
-function theme_watcher_help_page($content) {
+function theme_watcher_help_page($variables) {
   $output =  '<div id="watcher_help_page">';
-  $output .= $content;
+  $output .= $variables['content'];
   $output .= '</div>';
   return $output;
 }
@@ -187,9 +205,9 @@ function theme_watcher_help_page($content) {
  *    A themed help page
  *
  */
-function theme_watcher_help($content) {
+function theme_watcher_help($variables) {
   $output =  '<div id="watcher_help"><pre>';
-  $output .= $content;
+  $output .= $variables['help'];
   $output .= '</pre></div>';
   return $output;
 }
@@ -200,36 +218,39 @@ function theme_watcher_help($content) {
  * @param $defaults_text
  *      Localized message
  */
-function theme_watcher_settings_defaults_notice($defaults_text) {
-  return '<div class="watcher_settings_defaults_notice">'. $defaults_text .'</div>';
+function theme_watcher_settings_defaults_notice($variables) {
+  return '<div class="watcher_settings_defaults_notice">'. $variables['defaults_text'] .'</div>';
 }
 
 /**
- * Implementation of hook_theme()
+ * Implements hook_theme()
  */
 function watcher_theme($existing, $type, $theme, $path) {
   return array(
     'watcher_binder' => array(
-      'arguments' => array('intro_text' => null, 'posts_table_header' => null, 'posts_table_body' => null),
-  ),
+      'variables' => array('intro_text' => NULL, 'posts_table_header' => NULL, 'posts_table_body' => NULL),
+    ),
     'watcher_binder_email_icon' => array(
-      'arguments' => array('t' => null, 'type' => null, 'url' => null, 'query' => null),
-  ),
+      'variables' => array('t' => NULL, 'type' => NULL, 'url' => NULL, 'query' => NULL),
+    ),
     'watcher_binder_stop_watching_icon' => array(
-      'arguments' => array('url' => null, 'query' => null),
-  ),
+      'variables' => array('url' => NULL, 'query' => NULL),
+    ),
     'watcher_node_toggle_watching_link' => array(
-      'arguments' => array('uid' => null, 'nid' => null, 'query' => null, 'user_is_watching' => null, 't' => array()),
-  ),
+      'variables' => array('uid' => NULL, 'nid' => NULL, 'query' => NULL, 'user_is_watching' => NULL, 't' => array()),
+    ),
     'watcher_help_page' => array(
-      'arguments' => array('content' => null),
-  ),
+      'variables' => array('content'),
+    ),
     'watcher_help' => array(
-      'arguments' => array('content' => null),
-  ),
+      'variables' => array('content'),
+    ),
     'watcher_settings_defaults_notice' => array(
-      'arguments' => array('defaults_text' => null),
-  ),
+      'variables' => array('defaults_text'),
+    ),
+    'watcher_box' => array(
+      'variables' => array('title' => NULL, 'content' => NULL, 'region' => NULL)
+    ),
   );
 }
 
@@ -238,14 +259,31 @@ function watcher_theme($existing, $type, $theme, $path) {
  ***************************************************************************************/
 
 /**
- * Implementation of hook_perm()
+ * Implements hook_permission()
  */
-function watcher_perm() {
-  return array('administer watcher', 'use watcher', 'change own user settings', 'access help page', 'access others lists of watched posts');
+function watcher_permission() {
+  //TODO: Add description to the permissions
+  return array(
+    'administer watcher' => array(
+      'title' => t('Administer watcher module'),
+    ),
+    'use watcher' => array(
+      'title' => t('Use watcher'),
+    ),
+    'change own user settings' => array(
+      'title' => t('Change own user settings'),
+    ),
+    'access help page' => array(
+      'title' => t('Access help page'),
+    ),
+    'access others lists of watched posts' => array(
+      'title' => t('Access others lists of watched posts'),
+    ),
+  );
 }
 
 /**
- * Implementation of hook_help()
+ * Implements hook_help()
  */
 function watcher_help($path, $arg) {
   switch ($path) {
@@ -258,12 +296,12 @@ function watcher_help($path, $arg) {
 
       $help = htmlentities($help);
 
-      return theme('watcher_help', $help);
+      return theme('watcher_help', array('help' => $help));
   }
 }
 
 /**
- * Implementation of hook_menu().
+ * Implements hook_menu().
  */
 function watcher_menu() {
   global $user;
@@ -272,18 +310,18 @@ function watcher_menu() {
   // Include file
   $base_include = array(
     'file' => 'watcher.db.inc'
-    );
+  );
 
-    $items['user/%user/watcher'] = array(
+  $items['user/%user/watcher'] = array(
     'title' => 'My Watched Posts',
     'page callback' => '_watcher_binder',
     'page arguments' => array(1),
     'access callback' => '_watcher_menu_access_binder',
     'access arguments' => array(1),
     'type' => MENU_LOCAL_TASK,
-    ) + $base_include;
+  ) + $base_include;
 
-    $items['user/%user/watcher/binder'] = array(
+  $items['user/%user/watcher/binder'] = array(
     'title' => 'Watched Posts',
     'page callback' => '_watcher_binder',
     'page arguments' => array(1),
@@ -291,111 +329,111 @@ function watcher_menu() {
     'access arguments' => array(1),
     'weight' => 0,
     'type' => MENU_DEFAULT_LOCAL_TASK,
-    ) + $base_include;
+  ) + $base_include;
 
-    $items['user/%user/watcher/settings'] = array(
+  $items['user/%user/watcher/settings'] = array(
     'title' => 'Settings',
     'weight' => 5,
     'page callback' => 'drupal_get_form',
     'page arguments' => array('_watcher_user_settings', 1),
     'access arguments' => array('change own user settings'),
     'type' => MENU_IS_LOCAL_TASK
-    ) + $base_include;
+  ) + $base_include;
 
-    $items['user/%/watcher/help'] = array(
+  $items['user/%/watcher/help'] = array(
     'title' => 'Help',
     'weight' => 10,
     'page callback' => '_watcher_help_page',
     'access arguments' => array('access help page'),
     'type' => MENU_IS_LOCAL_TASK
-    ) + $base_include;
+  ) + $base_include;
 
 
-    // Callbacks for toggling
+  // Callbacks for toggling
 
-    $items['user/%user/watcher/toggle/%node'] = array(
+  $items['user/%user/watcher/toggle/%node'] = array(
     'title' => 'Watcher Toggle Watching Post',
     'page callback' => '_watcher_watch_toggle',
     'page arguments' => array(4),
     'access callback' => '_watcher_menu_access_toggle_watching_post',
     'access arguments' => array(1),
     'type' => MENU_CALLBACK
-    ) + $base_include;
+  ) + $base_include;
 
-    $items['user/%user/watcher/email_notifications_toggle'] = array(
+  $items['user/%user/watcher/email_notifications_toggle'] = array(
     'title' => 'Watcher Toggle Email Notifications',
     'page callback' => '_watcher_email_notifications_toggle',
     'access callback' => '_watcher_menu_access_toggle_email_notifications',
     'access arguments' => array(1),
     'type' => MENU_CALLBACK
-    ) + $base_include;
+  ) + $base_include;
 
-    // Unwatching for anonymous users
-    //
-    // NOTE: Path must not end with /%/%, else callback arguments will be garbled!
-    //       Even if we pass additional path args, such as arg(6) and arg(7),
-    //       we do not need to wildcard these.
+  // Unwatching for anonymous users
+  //
+  // NOTE: Path must not end with /%/%, else callback arguments will be garbled!
+  //       Even if we pass additional path args, such as arg(6) and arg(7),
+  //       we do not need to wildcard these.
 
-    $items['user/%user/watcher/toggle/%node/unwatch'] = array(
+  $items['user/%user/watcher/toggle/%node/unwatch'] = array(
     'page callback' => '_watcher_watch_toggle',
     'page arguments' => array(4, 6, 'node', 7),
     'access callback' => '_watcher_menu_access_toggle_watching_post',
     'access arguments' => array(1),
     'type' => MENU_CALLBACK
-    ) + $base_include;
+  ) + $base_include;
 
-    $items['user/%user/watcher/toggle/%node/unwatch-all'] = array(
+  $items['user/%user/watcher/toggle/%node/unwatch-all'] = array(
     'page callback' => '_watcher_watch_toggle',
     'page arguments' => array(4, 6, 'all', 7),
     'access callback' => '_watcher_menu_access_toggle_watching_post',
     'access arguments' => array(1),
     'type' => MENU_CALLBACK
-    ) + $base_include;
+  ) + $base_include;
 
-    // Administration Panel Settings
+  // Administration Panel Settings
 
-    $items['admin/settings/watcher'] = array(
+  $items['admin/config/watcher'] = array(
     'title' => 'Watcher',
     'description' => 'Modify the settings for Watcher module.',
     'page callback' => 'drupal_get_form',
     'page arguments' => array('_watcher_admin_settings'),
     'access arguments' => array('administer watcher'),
     'type' => MENU_NORMAL_ITEM,
-    ) + $base_include;
+  ) + $base_include;
 
-    $items['admin/settings/watcher/settings'] = array(
+  $items['admin/config/watcher/settings'] = array(
     'title' => 'Settings',
     'page callback' => 'drupal_get_form',
     'page arguments' => array('_watcher_admin_settings'),
     'access arguments' => array('administer watcher'),
     'type' => MENU_DEFAULT_LOCAL_TASK,
-    ) + $base_include;
+  ) + $base_include;
 
-    $items['admin/settings/watcher/stats'] = array(
+  $items['admin/config/watcher/stats'] = array(
     'title' => 'Statistics',
     'page callback' => 'drupal_get_form',
     'page arguments' => array('_watcher_admin_stats'),
     'access arguments' => array('administer watcher'),
     'type' => MENU_LOCAL_TASK,
-    ) + $base_include;
+  ) + $base_include;
 
-    $items['admin/settings/watcher/test'] = array(
+  $items['admin/config/watcher/test'] = array(
     'title' => 'Testing',
     'page callback' => 'drupal_get_form',
     'page arguments' => array('_watcher_admin_test'),
     'access arguments' => array('administer watcher'),
     'type' => MENU_LOCAL_TASK,
-    ) + $base_include;
+  ) + $base_include;
 
-    // Binder shortcut, redirect to user's My Watched Posts page
-    $items['user/watcher'] = array(
+  // Binder shortcut, redirect to user's My Watched Posts page
+  $items['user/watcher'] = array(
     'title' => 'My Watched Posts',
     'page callback' => '_watcher_binder_shortcut',
     'access callback' => '_watcher_menu_access_binder_shortcut',
     'type' => MENU_NORMAL_ITEM,
-    ) + $base_include;
+  ) + $base_include;
 
-    return $items;
+  return $items;
 }
 
 /**
@@ -442,83 +480,118 @@ function _watcher_menu_access_binder_shortcut() {
 }
 
 /**
- * Implementation of hook_nodeapi()
+ * Implements hook_nodeapi()
  */
-function watcher_nodeapi(&$node, $op, $a3, $a4) {
+//function watcher_nodeapi(&$node, $op, $a3, $a4) {
+//
+//  // Check whether this is one of the node types for which Watcher is enabled
+//  if (!_watcher_node_type_enabled($node)) {
+//    return FALSE;
+//  }
+//
+//  // Include DB dependent functions
+//  module_load_include('inc', 'watcher', 'watcher.db');
+//
+//  // Dispatch the operator.
+//  $function = '_watcher_hook_nodeapi_'. $op;
+//  if (function_exists($function)) {
+//    return $function($node, $a3, $a4);
+//  }
+//}
 
+/**
+ * Implements hook_node_view()
+ */
+function watcher_node_view($node, $view_mode, $langcode) {
+  global $user;
   // Check whether this is one of the node types for which Watcher is enabled
   if (!_watcher_node_type_enabled($node)) {
-    return false;
+    return FALSE;
   }
-
   // Include DB dependent functions
   module_load_include('inc', 'watcher', 'watcher.db');
-
-  // Dispatch the operator.
-  $function = '_watcher_hook_nodeapi_'. $op;
-  if (function_exists($function)) {
-    return $function($node, $a3, $a4);
-  }
-}
-
-/**
- * Implementation of hook_nodeapi(), op: view
- */
-function _watcher_hook_nodeapi_view(&$node, $a3, $a4) {
-  global $user;
+  
   if (user_access('use watcher')) {
-    _watcher_node_watch_link($node, $a3, $a4);
+    _watcher_node_watch_link($node, $view_mode);
   }
 }
 
 /**
- * Implementation of hook_nodeapi(), op: insert
+ * Implements hook_node_insert()
  */
-function _watcher_hook_nodeapi_insert(&$node, $a3, $a4) {
+function watcher_node_insert($node) {
   global $user;
+  // Check whether this is one of the node types for which Watcher is enabled
+  if (!_watcher_node_type_enabled($node)) {
+    return FALSE;
+  }
+  // Include DB dependent functions
+  module_load_include('inc', 'watcher', 'watcher.db');
+  
   if ($user->uid) {
     _watcher_user_autowatch_node_insert($node->nid);
   }
 }
 
 /**
- * Implementation of hook_nodeapi(), op: update
+ * Implements hook_node_update()
  */
-function _watcher_hook_nodeapi_update(&$node, $a3, $a4) {
+function watcher_node_update($node) {
+  // Check whether this is one of the node types for which Watcher is enabled
+  if (!_watcher_node_type_enabled($node)) {
+    return FALSE;
+  }
+  // Include DB dependent functions
+  module_load_include('inc', 'watcher', 'watcher.db');
+  
   _watcher_email_notify_node_update($node);
 }
 
 /**
- * Implementation of hook_nodeapi(), op: delete
+ * Implements hook_node_delete()
  */
-function _watcher_hook_nodeapi_delete(&$node, $a3, $a4) {
+function watcher_node_delete($node) {
+  // Check whether this is one of the node types for which Watcher is enabled
+  if (!_watcher_node_type_enabled($node)) {
+    return FALSE;
+  }
+  // Include DB dependent functions
+  module_load_include('inc', 'watcher', 'watcher.db');
+  
   _watcher_db_delete_nid($node->nid);
 }
 
 /**
- * Implementation of hook_comment()
+ * Implements hook_comment()
  */
-function watcher_comment($comment, $op) {
-
-  // Include DB dependent functions
-  module_load_include('inc', 'watcher', 'watcher.db');
-
-  // Dispatch the operator.
-  $function = '_watcher_hook_comment_'. $op;
-  if (function_exists($function)) {
-    return $function($comment);
-  }
-}
+//function watcher_comment($comment, $op) {
+//
+//  // Include DB dependent functions
+//  module_load_include('inc', 'watcher', 'watcher.db');
+//
+//  // Dispatch the operator.
+//  $function = '_watcher_hook_comment_'. $op;
+//  if (function_exists($function)) {
+//    return $function($comment);
+//  }
+//}
 
 /**
- * Implementation of hook_comment(), op: insert
+ * Implements hook_comment_insert()
  */
-function _watcher_hook_comment_insert($comment) {
+function watcher_comment_insert($comment) {
   global $user;
+  
+  // Include DB dependent functions
+  module_load_include('inc', 'watcher', 'watcher.db');
+  
+  // comment_publish is passed a comment as an object so we have to cast
+  // it as an array first
+  $comment = (array) $comment;
 
   // Check whether this is one of the node types for which Watcher is enabled
   if (!_watcher_node_type_enabled($comment['nid'])) {
-    return false;
+    return FALSE;
   }
 
   // Only add the node to user's watch list if this is a non-anonymous user
@@ -534,22 +607,24 @@ function _watcher_hook_comment_insert($comment) {
 }
 
 /**
- * Implementation of hook_comment(), op: publish
+ * Implements hook_comment_publish()
  *
  * @param $comment A comment object.
  */
-function _watcher_hook_comment_publish($comment) {
-
+function watcher_comment_publish($comment) {
+  // Include DB dependent functions
+  module_load_include('inc', 'watcher', 'watcher.db');
+  
   // comment_publish is passed a comment as an object so we have to cast
   // it as an array first
   $comment = (array) $comment;
 
   // Check whether this is one of the node types for which Watcher is enabled
   if (!_watcher_node_type_enabled($comment['nid'])) {
-    return false;
+    return FALSE;
   }
 
-  $comment_author = user_load(array('uid' => $comment['uid']));
+  $comment_author = user_load($comment['uid']);
 
   // If this comment was unpublished as a result of it requiring approval
   // notify the users watching the node now that it's deemed worthy to publish
@@ -560,22 +635,28 @@ function _watcher_hook_comment_publish($comment) {
 }
 
 /**
- * Implementation of hook_comment(), op: update
+ * Implements hook_comment_update()
  *
  * @param $comment An array of comment edit form values.
  */
-function _watcher_hook_comment_update($comment) {
-
+function watcher_comment_update($comment) {
+  // Include DB dependent functions
+  module_load_include('inc', 'watcher', 'watcher.db');
+  
+  // comment_publish is passed a comment as an object so we have to cast
+  // it as an array first
+  $comment = (array) $comment;
+  
   // Check whether this is one of the node types for which Watcher is enabled
   if (!_watcher_node_type_enabled($comment['nid'])) {
-    return false;
+    return FALSE;
   }
 
   // Make sure the comment is published
   if ($comment['status'] == COMMENT_PUBLISHED) {
 
-    // If the comment author is anonymous, the uid field is null
-    $comment_author = user_load(array('uid' => (is_null($commment['uid']) ? 0 : $commment['uid'])));
+    // If the comment author is anonymous, the uid field is NULL
+    $comment_author = user_load((is_NULL($comment['uid']) ? 0 : $commment['uid']));
 
     // If this comment was unpublished as a result of it requiring approval
     // notify the users watching the node now that it's deemed worthy to publish
@@ -589,36 +670,38 @@ function _watcher_hook_comment_update($comment) {
 
 
 /**
- * Implementation of hook_user()
+ * Implements hook_user()
  */
-function watcher_user($type, &$edit, &$account) {
-
-  // Include DB dependent functions
-  module_load_include('inc', 'watcher', 'watcher.db');
-
-  // Dispatch the operator.
-  $function = '_watcher_hook_user_'. $type;
-  if (function_exists($function)) {
-    $function($edit, $account);
-  }
-}
+//function watcher_user($type, &$edit, &$account) {
+//
+//  // Include DB dependent functions
+//  module_load_include('inc', 'watcher', 'watcher.db');
+//
+//  // Dispatch the operator.
+//  $function = '_watcher_hook_user_'. $type;
+//  if (function_exists($function)) {
+//    $function($edit, $account);
+//  }
+//}
 
 /**
- * Implementation of hook_user(), op: insert
+ * Implements hook_user_insert()
  */
-function _watcher_hook_user_insert($edit, $account, $category = NULL) {
+function watcher_user_insert(&$edit, $account, $category = NULL) {
+  // Include DB dependent functions
+  module_load_include('inc', 'watcher', 'watcher.db');
   _watcher_user_settings_update_defaults();
 }
 
 /**
- * Implementation of hook_user(), op: delete
+ * Implements hook_user_delete()
  */
-function _watcher_hook_user_delete($edit, $account, $category = NULL) {
+function watcher_user_delete($account) {
   _watcher_db_delete_user_settings($account->uid);
 }
 
 /**
- * Implementation of hook_cron()
+ * Implements hook_cron()
  */
 function watcher_cron() {
 
@@ -632,7 +715,7 @@ function watcher_cron() {
 }
 
 /**
- * Implementation of hook_mail()
+ * Implements hook_mail()
  */
 function watcher_mail($key, &$message, $params) {
   $message['subject'] = $params['subject'];
@@ -640,9 +723,9 @@ function watcher_mail($key, &$message, $params) {
 }
 
 /**
- * Implementation of hook_exit()
+ * Implements hook_exit()
  */
-function watcher_exit() {
+function watcher_exit($destination = NULL) {
   _watcher_email_notifications_send_instant();
 }
 
@@ -653,7 +736,7 @@ function watcher_exit() {
 /**
  * This is our admin settings page
  */
-function _watcher_admin_settings(&$form_state) {
+function _watcher_admin_settings($form, $form_state) {
 
   global $user;
 
@@ -694,12 +777,12 @@ function _watcher_admin_settings_content_types(&$form) {
     '#type' => 'fieldset',
     '#title' => t('Watchable Content Types'),
     '#description' => t('Select the content types that may be watched.'),
-    '#collapsible' => true,
-    '#collapsed' => true,
+    '#collapsible' => TRUE,
+    '#collapsed' => TRUE,
   );
 
   // Display error message if no node types have been selected
-  $watchable_node_types = variable_get('watcher_content_types', false);
+  $watchable_node_types = variable_get('watcher_content_types', FALSE);
   if (!$watchable_node_types) {
     drupal_set_message(t("You haven't selected any watchable content types. This module will not work until you do so."), 'error');
   }
@@ -707,7 +790,7 @@ function _watcher_admin_settings_content_types(&$form) {
   $form['contenttypes']['watcher_content_types'] = array(
       '#type' => 'checkboxes',
       '#default_value' => $watchable_node_types,
-      '#options' => node_get_types('names'),
+      '#options' => node_type_get_names(),
       '#default_value' => variable_get('watcher_content_types', array()),
   );
 }
@@ -720,15 +803,15 @@ function _watcher_admin_settings_watch_toggle_link(&$form) {
   $form['togglelink'] = array(
     '#type' => 'fieldset',
     '#title' => t('Watch Toggle Link'),
-    '#collapsible' => true,
-    '#collapsed' => true,
+    '#collapsible' => TRUE,
+    '#collapsed' => TRUE,
   );
 
   $form['togglelink']['watcher_toggle_link_in_teaser'] = array(
       '#type' => 'checkbox',
       '#title' => t('Display "watch this post" toggle link in teasers.'),
       '#description' => t('Determines whether or not to show the "watch this post" toggle link in node teasers (used on front page and content listings). Teasers are the shortened down version of a node, often shown on a site\'s frontpage or on pages that summarize content. If disabled, link will only be shown when nodes are shown as pages (full view).'),
-      '#default_value' => variable_get('watcher_toggle_link_in_teaser', false),
+      '#default_value' => variable_get('watcher_toggle_link_in_teaser', FALSE),
   );
 }
 
@@ -745,12 +828,12 @@ function _watcher_admin_settings_personal_binder(&$form) {
   $form['display'] = array(
     '#type' => 'fieldset',
     '#title' => t('Display Settings for Personal Binder'),
-    '#collapsible' => true,
-    '#collapsed' => true,
+    '#collapsible' => TRUE,
+    '#collapsed' => TRUE,
   );
 
   $form['display'][] = array(
-      '#value' => '<p>'. l(t('Click here to view your personal binder'), "user/$user->uid/watcher") .'</p>',
+      '#markup' => '<p>'. l(t('Click here to view your personal binder'), "user/$user->uid/watcher") .'</p>',
   );
 
   $form['display']['watcher_display_intro_text'] = array(
@@ -796,12 +879,12 @@ function _watcher_admin_settings_email_notifications(&$form) {
   $form['notifications'] = array(
     '#type' => 'fieldset',
     '#title' => t('Settings for Email Notifications'),
-    '#collapsible' => true,
-    '#collapsed' => true,
+    '#collapsible' => TRUE,
+    '#collapsed' => TRUE,
   );
 
   $form['notifications'][] = array(
-      '#value' => '<div style="border: 1px solid #0062A0; margin: 1em; padding: 0 0 0 1em; background: #CBE2F1; font-weight: bold;">',
+      '#markup' => '<div style="border: 1px solid #0062A0; margin: 1em; padding: 0 0 0 1em; background: #CBE2F1; font-weight: bold;">',
   );
 
   $form['notifications']['watcher_email_notifications_enabled'] = array(
@@ -811,7 +894,7 @@ function _watcher_admin_settings_email_notifications(&$form) {
   );
 
   $form['notifications'][] = array(
-      '#value' => '</div>',
+      '#markup' => '</div>',
   );
 
   $form['notifications']['watcher_email_notifications_method'] = array(
@@ -867,8 +950,8 @@ function _watcher_admin_settings_email_notifications(&$form) {
     '#type' => 'fieldset',
     '#title' => t('Notification Message Templates'),
     '#description' => t('These message templates are used for notifications and confirmation messages. You may edit them if you like. Tokens are in [brackets] and act as placeholders for variables, such as URLs, usernames and email addresses, and will be replaced when the email is sent. <strong>You cannot use HTML code in your message templates.</strong>'),
-    '#collapsible' => true,
-    '#collapsed' => true,
+    '#collapsible' => TRUE,
+    '#collapsed' => TRUE,
   );
 
   // Header
@@ -883,12 +966,12 @@ function _watcher_admin_settings_email_notifications(&$form) {
   $form['notifications']['templates']['tokens_header'] = array(
       '#type' => 'fieldset',
       '#title' => t('Additional Tokens for Header'),
-      '#collapsible' => true,
-      '#collapsed' => true,
+      '#collapsible' => TRUE,
+      '#collapsed' => TRUE,
   );
 
   $form['notifications']['templates']['tokens_header'][] = array(
-        '#value' => theme('token_help', 'global'),
+        '#markup' => theme('token_tree', array('token_types' => array('global'))),
   );
 
   // Footer
@@ -917,12 +1000,12 @@ function _watcher_admin_settings_email_notifications(&$form) {
   $form['notifications']['templates']['tokens_footer'] = array(
       '#type' => 'fieldset',
       '#title' => t('Additional Tokens for Footers'),
-      '#collapsible' => true,
-      '#collapsed' => true,
+      '#collapsible' => TRUE,
+      '#collapsed' => TRUE,
   );
 
   $form['notifications']['templates']['tokens_footer'][] = array(
-        '#value' => theme('token_help', 'global'),
+        '#markup' => theme('token_tree', array('token_types' => array('global'))),
   );
 
   // Template for Messages about Node Updates
@@ -931,18 +1014,18 @@ function _watcher_admin_settings_email_notifications(&$form) {
       '#type' => 'textarea',
       '#title' => t('Message Body for Node Updates'),
       '#default_value' => variable_get('watcher_notifications_templates_body_node', $templates['body_node_update']),
-      '#description' => t('<p>The following tokens are available:</p><ul><li>[node-url]</li></ul>')
+      '#description' => t('<p>The following tokens are available:</p><ul><li>[node:url]</li></ul>')
   );
 
   $form['notifications']['templates']['tokens_nodes'] = array(
       '#type' => 'fieldset',
       '#title' => t('Additional Tokens for Nodes'),
-      '#collapsible' => true,
-      '#collapsed' => true,
+      '#collapsible' => TRUE,
+      '#collapsed' => TRUE,
   );
 
   $form['notifications']['templates']['tokens_nodes'][] = array(
-     '#value' => theme('token_help', 'node'),
+     '#markup' => theme('token_tree', array('token_types' => array('node'))),
   );
 
   // Template for Messages about New Comments
@@ -951,18 +1034,18 @@ function _watcher_admin_settings_email_notifications(&$form) {
       '#type' => 'textarea',
       '#title' => t('Message Body for New Comments'),
       '#default_value' => variable_get('watcher_notifications_templates_body_cmt', $templates['body_comment_insert']),
-      '#description' => t('<p>The following tokens are available:</p><ul><li>[comment-excerpt]</li><li>[node-url]</li><li>[comment-url]</li><li>[comment-reply-url]</li></ul>')
+      '#description' => t('<p>The following tokens are available:</p><ul><li>[comment-excerpt]</li><li>[node:url]</li><li>[comment:url]</li><li>[comment-reply-url]</li></ul>')
   );
 
   $form['notifications']['templates']['tokens_comments'] = array(
       '#type' => 'fieldset',
       '#title' => t('Additional Tokens for Comments'),
-      '#collapsible' => true,
-      '#collapsed' => true,
+      '#collapsible' => TRUE,
+      '#collapsed' => TRUE,
   );
 
   $form['notifications']['templates']['tokens_comments'][] = array(
-      '#value' => theme('token_help', 'comment') . theme('token_help', 'node'),
+      '#markup' => theme('token_tree', array('token_types' => array('comment', 'node'))),
   );
 
   // Template for Confirmation Messages to anonymous users
@@ -971,7 +1054,7 @@ function _watcher_admin_settings_email_notifications(&$form) {
       '#type' => 'textarea',
       '#title' => t('Message Body for Confirmation Messages'),
       '#default_value' => variable_get('watcher_notifications_templates_body_confirm', $templates['body_confirm']),
-      '#description' => t('<p>The text above will be included in confirmation messages sent to anonymous users when they start watching a node.:</p><p>The following tokens are available:</p><ul><li>[node-url]</li></ul>')
+      '#description' => t('<p>The text above will be included in confirmation messages sent to anonymous users when they start watching a node.:</p><p>The following tokens are available:</p><ul><li>[node:url]</li></ul>')
   );
 }
 
@@ -987,8 +1070,8 @@ function _watcher_admin_settings_default_user_settings(&$form) {
     '#type' => 'fieldset',
     '#title' => t('Default User Settings'),
     '#description' => t('These will set the defaults in every user\'s personal settings. Settings you make here will affect the settings of every user that hasn\'t customized his or her settings. This setting will currently affect <strong>!numusers</strong> users who have not customized their settings.', array('!numusers' => $stats['num_users_no_settings'])),
-    '#collapsible' => true,
-    '#collapsed' => true,
+    '#collapsible' => TRUE,
+    '#collapsed' => TRUE,
   );
 
   $form['default']['watcher_default_settings'] = array(
@@ -1019,8 +1102,8 @@ function _watcher_admin_settings_help(&$form) {
     '#type' => 'fieldset',
     '#title' => t('Help Page'),
     '#description' => t('This help text is displayed if the user clicks the Help link in the list of watched posts. You can customize it below. To apply your own CSS rules to this page you can use the <code>#watcher_help_page</code> selector.'),
-    '#collapsible' => true,
-    '#collapsed' => true,
+    '#collapsible' => TRUE,
+    '#collapsed' => TRUE,
   );
 
   $form['help']['watcher_help_text'] = array(
@@ -1031,7 +1114,7 @@ function _watcher_admin_settings_help(&$form) {
   );
 
   $form['help'][] = array(
-    '#value' => l(t('Preview help page'), "user/$user->uid/watcher/help"),
+    '#markup' => l(t('Preview help page'), "user/$user->uid/watcher/help"),
   );
 }
 
@@ -1057,7 +1140,7 @@ function _watcher_admin_stats() {
     );
 
     $form['notification_queue_table'][] = array(
-        '#value' => theme('table', array(), $table_body),
+        '#markup' => theme('table', array('rows' => $table_body)),
     );
 
 
@@ -1065,16 +1148,16 @@ function _watcher_admin_stats() {
         '#type' => 'fieldset',
         '#title' => t('Table Content'),
         '#description' => t('This is the content of the notification queue table.'),
-        '#collapsed' => true,
-        '#collapsible' => true,
+        '#collapsed' => TRUE,
+        '#collapsible' => TRUE,
     );
     $form['notification_queue_table']['content'][] = array(
-        '#value' => theme('table', $stats['data']['header'], $stats['data']['content']),
+        '#markup' => theme('table', array('header' => $stats['data']['header'], 'rows' => $stats['data']['content'])),
     );
   }
   else {
     $form['notification_queue_table'][] = array(
-      '#value' => t('There are no notifications in the queue.'),
+      '#markup' => t('There are no notifications in the queue.'),
     );
   }
   //////////////// Watched Nodes Table Statistics ////////////////
@@ -1092,7 +1175,7 @@ function _watcher_admin_stats() {
   );
 
   $form['watched_nodes_users_table'][] = array(
-        '#value' => theme('table', array(), $table_body),
+        '#markup' => theme('table', array('rows' => $table_body)),
   );
 
 
@@ -1111,7 +1194,7 @@ function _watcher_admin_stats() {
   );
 
   $form['user_settings_table'][] = array(
-        '#value' => theme('table', array(), $table_body),
+        '#markup' => theme('table', array('rows' => $table_body)),
   );
 
 
@@ -1130,12 +1213,12 @@ function _watcher_admin_test() {
 
   if (!variable_get('watcher_email_notifications_enabled', 1)) {
     $form[] = array(
-      '#value' => '<p><strong>'. t('Email notifications are NOT enabled. You can use the diagnostics tools anyway but regular notifications will not be sent.') .'</strong></p>',
+      '#markup' => '<p><strong>'. t('Email notifications are NOT enabled. You can use the diagnostics tools anyway but regular notifications will not be sent.') .'</strong></p>',
     );
   }
 
   $form[] = array(
-    '#value' => t("If you're experiencing problems with the module such as messages not being delivered et c, you can use the diagnostic tools on this page to send test notifications. The <a href=\"!statpage\">statistics page</a> also contains valuable information for troubleshooting.", array('!statpage' => url('admin/settings/watcher/stats')))
+    '#markup' => t("If you're experiencing problems with the module such as messages not being delivered et c, you can use the diagnostic tools on this page to send test notifications. The <a href=\"!statpage\">statistics page</a> also contains valuable information for troubleshooting.", array('!statpage' => url('admin/settings/watcher/stats')))
   );
 
   $form['create_test_notification'] = array(
@@ -1165,19 +1248,19 @@ function _watcher_admin_test() {
   $method = variable_get('watcher_email_notifications_method', 'cron');
 
   $form['send_notifications_in_queue'][] = array(
-      '#value' => '<p>'. t('Your currently selected method for sending notifications in queue is <strong>!method</strong>.', array('!method' => $method)) .'</p>',
+      '#markup' => '<p>'. t('Your currently selected method for sending notifications in queue is <strong>!method</strong>.', array('!method' => $method)) .'</p>',
   );
 
   $stats = _watcher_db_stats_notification_queue();
 
   $form['send_notifications_in_queue']['stats'] = array(
-      '#value' => '<p>'. t('There are currently <strong>!num</strong> !notification_plural in the queue.', array('!num' => $stats['num_rows'], '!notification_plural' => format_plural($stats['num_rows'], 'notification', 'notifications')))  .'</p>',
+      '#markup' => '<p>'. t('There are currently <strong>!num</strong> !notification_plural in the queue.', array('!num' => $stats['num_rows'], '!notification_plural' => format_plural($stats['num_rows'], 'notification', 'notifications')))  .'</p>',
   );
 
   if ($stats['num_rows']) {
     if ($method == 'cron' ) {
       $form['send_notifications_in_queue']['cron'] = array(
-          '#value' => '<p><strong>'. l(t('Click here to run cron manually and SEND messages in queue'), 'admin/reports/status/run-cron', array('query' => 'destination=admin/settings/watcher/test')) .'</strong></p>',
+          '#markup' => '<p><strong>'. l(t('Click here to run cron manually and SEND messages in queue'), 'admin/reports/status/run-cron', array('query' => array('destination' => 'admin/settings/watcher/test'))) .'</strong></p>',
       );
     }
     else {
@@ -1189,7 +1272,7 @@ function _watcher_admin_test() {
     }
 
     $form['send_notifications_in_queue'][] = array(
-      '#value' => '<p>- or -</p>',
+      '#markup' => '<p>- or -</p>',
     );
 
     $form['send_notifications_in_queue']['empty_queue'] = array(
@@ -1205,7 +1288,7 @@ function _watcher_admin_test() {
 /**
  * Submit handler for test form: Create node update notification
  */
-function _watcher_admin_test_create_node_update_notification($form, &$form_state) {
+function _watcher_admin_test_create_node_update_notification($form, $form_state) {
   global $user;
 
   // Prepare an array of recipients
@@ -1226,7 +1309,7 @@ function _watcher_admin_test_create_node_update_notification($form, &$form_state
 /**
  * Submit handler for test form: Create new comment notification
  */
-function _watcher_admin_test_create_new_comment_notification($form, &$form_state) {
+function _watcher_admin_test_create_new_comment_notification($form, $form_state) {
 
   global $user;
 
@@ -1234,7 +1317,7 @@ function _watcher_admin_test_create_new_comment_notification($form, &$form_state
   $recipients = array($user->uid => $user);
 
   if ($newest_cid = _watcher_db_get_newest_comment()) {
-    $comment = (array) _comment_load($newest_cid);
+    $comment = (array) comment_load($newest_cid);
     $subject = t('TEST: New comment posted');
     if (_watcher_email_notify_comment_insert_add_to_queue($recipients, $subject, $comment)) {
       drupal_set_message(t('A test notification (new comment) has been created.'));
@@ -1248,15 +1331,15 @@ function _watcher_admin_test_create_new_comment_notification($form, &$form_state
 /**
  * Submit handler for test form: Send notifications in queue instantly
  */
-function _watcher_admin_test_send_notifications_in_queue_instant($form, &$form_state) {
-  _watcher_static('messages to send', true);
+function _watcher_admin_test_send_notifications_in_queue_instant($form, $form_state) {
+  _watcher_static('messages to send', TRUE);
   drupal_set_message(t('Notifications have been sent using instant method.'));
 }
 
 /**
  * Submit handler for test form: Empty notification queue
  */
-function _watcher_admin_test_empty_queue($form, &$form_state) {
+function _watcher_admin_test_empty_queue($form, $form_state) {
   if (_watcher_db_delete_users_notification_queue_all()) {
     drupal_set_message(t('Watcher Notification Queue has been emptied.'));
   }
@@ -1306,6 +1389,7 @@ function _watcher_binder($account) {
   drupal_add_js(drupal_get_path('module', 'watcher') .'/js/watcher.js');
   drupal_add_js(array('watcher' => $tstrings), 'setting');
 
+
   //////////// Set up table header ////////////////
   $header = array();
 
@@ -1321,7 +1405,7 @@ function _watcher_binder($account) {
   );
 
   // post author
-  if (variable_get('watcher_display_post_author', true)) {
+  if (variable_get('watcher_display_post_author', TRUE)) {
     $header[] = array(
       'data' => t('Author'),
       'field' => 'u.name',
@@ -1363,36 +1447,37 @@ function _watcher_binder($account) {
 
   ///////////// Process the result set //////////////
   $rows = array();
-  while ($node = db_fetch_object($result)) {
+  foreach ($result as $node) {
 
     // Determine the number of comments:
     $comments = _watcher_binder_comment_count($node);
 
     // Generate destination and token query
-    $link_query = drupal_get_destination() ."&token=". _watcher_get_token($node->nid);
+    $link_query = drupal_get_destination();
+    $link_query['token'] = _watcher_get_token($node->nid);
 
     // Populate table
     $row = array();
 
     // Get name of node type
     if (variable_get('watcher_display_node_type', 0)) {
-      $row[] = check_plain(node_get_types('name', $node->type));
+      $row[] = check_plain(node_type_get_name($node));
     }
 
     // Node title
-    $row[] = l($node->title, "node/$node->nid") .' '. theme('mark', node_mark($node->nid, $node->changed));
+    $row[] = l($node->title, "node/$node->nid") .' '. theme('mark', array('type' => node_mark($node->nid, $node->changed)));
 
     // Author user name
     if (variable_get('watcher_display_post_author', 0)) {
-      $row[] = theme('username', $node);
+      $row[] = theme('username', array('name' => $node->name));
     }
 
     // Post added
-    $row[] = ($node->added ? t('!time ago', array('!time' => format_interval(time() - $node->added))) : null );
+    $row[] = ($node->added ? t('!time ago', array('!time' => format_interval(REQUEST_TIME - $node->added))) : NULL );
 
     // Post last updated
     if (variable_get('watcher_display_last_updated', 0)) {
-      $row[] = t('!time ago', array('!time' => format_interval(time() - $node->last_updated)));
+      $row[] = t('!time ago', array('!time' => format_interval(REQUEST_TIME - $node->last_updated)));
     }
 
     // Number of comments
@@ -1403,12 +1488,12 @@ function _watcher_binder($account) {
 
     // Email notification status icon
     if ($user_is_owner && $emails_enabled) {
-      $row[] = theme('watcher_binder_email_icon', $tstrings, ($node->send_email ? 'enabled' : 'disabled'), "user/$uid/watcher/email_notifications_toggle/$node->nid", $link_query);
+      $row[] = theme('watcher_binder_email_icon', array('t' => $tstrings, 'type' => ($node->send_email ? 'enabled' : 'disabled'), 'url' => "user/$uid/watcher/email_notifications_toggle/$node->nid", 'query' => $link_query));
     }
 
     // Stop watching icon
     if ($user_is_owner) {
-      $row[] = theme('watcher_binder_stop_watching_icon', "user/$uid/watcher/toggle/$node->nid", $link_query);
+      $row[] = theme('watcher_binder_stop_watching_icon', array('url' => "user/$uid/watcher/toggle/$node->nid", 'query' => $link_query));
     }
 
     $rows[] = $row;
@@ -1429,7 +1514,7 @@ function _watcher_binder($account) {
 
   //////////////// Generate page content /////////////
   $intro_text = filter_xss_admin(variable_get('watcher_display_intro_text', $templates['watcher_display_intro_text']));
-  $output = theme('watcher_binder', $intro_text, $header, $rows);
+  $output = theme('watcher_binder', array('intro_text' => $intro_text, 'posts_table_header' => $header, 'posts_table_body' => $rows));
 
   return $output;
 }
@@ -1445,7 +1530,7 @@ function _watcher_binder_shortcut() {
 /**
  * Provide a user settings page for the module
  */
-function _watcher_user_settings(&$form_state, $account) {
+function _watcher_user_settings($form, &$form_submit, $account) {
 
   global $user;
 
@@ -1466,7 +1551,7 @@ function _watcher_user_settings(&$form_state, $account) {
 
   if ($defaults) {
     $form[] = array(
-      '#value' => theme('watcher_settings_defaults_notice', $defaults_text),
+      '#markup' => theme('watcher_settings_defaults_notice', array('defaults_text' => $defaults_text)),
     );
   }
 
@@ -1475,8 +1560,8 @@ function _watcher_user_settings(&$form_state, $account) {
     $form['email'] = array(
       '#type' => 'fieldset',
       '#title' => t('Email Notification Settings'),
-      '#collapsible' => false,
-      '#collapsed' => false,
+      '#collapsible' => FALSE,
+      '#collapsed' => FALSE,
     );
 
     $form['email']['watcher_automatic_enable_notifications'] = array(
@@ -1486,7 +1571,7 @@ function _watcher_user_settings(&$form_state, $account) {
     );
 
     $form['email'][] = array(
-        '#value' => '<div style="height: .5em"></div>'
+        '#markup' => '<div style="height: .5em"></div>'
         );
 
         $form['email']['watcher_notifications_updates'] = array(
@@ -1506,8 +1591,8 @@ function _watcher_user_settings(&$form_state, $account) {
   $form['autowatch'] = array(
     '#type' => 'fieldset',
     '#title' => t('Watch Automatically'),
-    '#collapsible' => false,
-    '#collapsed' => false,
+    '#collapsible' => FALSE,
+    '#collapsed' => FALSE,
   );
 
   $form['autowatch']['watcher_autowatch_commented_on'] = array(
@@ -1526,8 +1611,8 @@ function _watcher_user_settings(&$form_state, $account) {
     '#type' => 'fieldset',
     '#title' => t('Sharing'),
     '#description' => t('By sharing your list of watched posts, other users can see it but they cannot remove or add posts or change it in any way.'),
-    '#collapsible' => false,
-    '#collapsed' => false,
+    '#collapsible' => FALSE,
+    '#collapsed' => FALSE,
   );
 
   $form['sharing']['watcher_share_binder'] = array(
@@ -1567,7 +1652,7 @@ function _watcher_help_page() {
   $text = filter_xss_admin(variable_get('watcher_help_text', $templates['watcher_help_text']));
 
   // Return a themed help page
-  return theme('watcher_help_page', $text);
+  return theme('watcher_help_page', array('content' => $text));
 }
 
 
@@ -1590,7 +1675,7 @@ function _watcher_help_page() {
  *
  * TODO: Refactor into several functions
  */
-function _watcher_watch_toggle($node, $mail = null, $unwatch = null, $confirm = null) {
+function _watcher_watch_toggle($node, $mail = NULL, $unwatch = NULL, $confirm = NULL) {
   $nid = $node->nid;
   $token = $_REQUEST['token'];
 
@@ -1604,7 +1689,7 @@ function _watcher_watch_toggle($node, $mail = null, $unwatch = null, $confirm =
   global $user;
 
   // Are email notifications enabled?
-  $email_notifications = variable_get('watcher_email_notifications_enabled', true);
+  $email_notifications = variable_get('watcher_email_notifications_enabled', TRUE);
 
   // Is this an anonymous user?
   $anonymous = !((bool) $user->uid);
@@ -1619,7 +1704,7 @@ function _watcher_watch_toggle($node, $mail = null, $unwatch = null, $confirm =
   }
 
   // Is this an asynchronous request?
-  $async = $_GET['async'];
+  $async = isset($_GET['async']) ? $_GET['async'] : FALSE;
 
   // Get destination for redirection later on
   $dest = drupal_get_destination();
@@ -1648,16 +1733,15 @@ function _watcher_watch_toggle($node, $mail = null, $unwatch = null, $confirm =
     }
 
     // Unwatching all nodes being watched
-
     if ($unwatch == 'all') {
       if ($confirm != 'confirm') {
-
-        $link_query = "token=$token";
-
+        
+        $link_query['token'] = $token;
+        
         // Confirm the action
         $out = array();
         $out[] = array(
-          '#value' => '<h3>' . t('Are you sure you want to STOP watching all posts %email currently watches on this site? This action cannot be undone.', array('%email' =>  check_plain($recipient_user->mail))) . '</h3>' . '<p style="font-weight: bold;">'. l('Yes, I am sure.', 'user/'. $user->uid .'/watcher/toggle/'. $nid .'/unwatch-all/'. $mail .'/confirm', array('query' => $link_query)) .'</p>',
+          '#markup' => '<h3>' . t('Are you sure you want to STOP watching all posts %email currently watches on this site? This action cannot be undone.', array('%email' => check_plain($recipient_user->mail))) . '</h3>' . '<p style="font-weight: bold;">'. l('Yes, I am sure.', 'user/'. $user->uid .'/watcher/toggle/'.$nid.'/unwatch-all/'.$mail.'/confirm') .'</p>',
         );
         return drupal_render($out);
       }
@@ -1666,7 +1750,7 @@ function _watcher_watch_toggle($node, $mail = null, $unwatch = null, $confirm =
 
           // Remove NID from session to mark it as no longer being watched
           $nids = _watcher_session('watching');
-          while ($row = db_fetch_object($db_result)) {
+          foreach ($db_result as $row) {
             $watched_nids[] = $row->nid;
             if (is_array($nids)) {
               unset($nids[$row->nid]);
@@ -1701,10 +1785,12 @@ function _watcher_watch_toggle($node, $mail = null, $unwatch = null, $confirm =
 
 
   // Handle watching and unwatching for logged-in users
-  else {
-
-    $link_query = $dest ."&token=$token";
 
+  else {
+    
+    $link_query = $dest;
+    $link_query['token'] = $token;
+    
     if (_watcher_user_is_watching_node($user, $nid)) {
       if (_watcher_user_unset_watching_nodes(array($nid), $user)) {
         $message = t('You are no longer watching <em>!ntitle</em>. <strong><a href="!undo">Undo</a></strong>', array('!ntitle' => check_plain($node->title), '!undo' => url("user/$user->uid/watcher/toggle/$node->nid", array('query' => $link_query))));
@@ -1739,12 +1825,12 @@ function _watcher_watch_toggle($node, $mail = null, $unwatch = null, $confirm =
 /**
  * Toggle email notifications for a post
  *
- * @param $nid Node ID of the node we want to toggle notifications forr
+ * @param $nid Node ID of the node we want to toggle notifications for
  */
 function _watcher_email_notifications_toggle($nid) {
   global $user;
   $uid = $user->uid;
-
+  
   $token = $_REQUEST['token'];
 
   // Validate token
@@ -1757,7 +1843,7 @@ function _watcher_email_notifications_toggle($nid) {
   // Toggle
   if (_watcher_user_is_watching_node($user, $nid)) {
     if (_watcher_email_notifications_status_for_user_node($nid, $uid)) {
-      _watcher_email_notifications_disable($nid, $uid);
+      _watcher_email_notifications_disable($nid, $user);
       $nstatus['status'] = 'disabled';
     }
     else {
@@ -1833,9 +1919,9 @@ function _watcher_email_notify_node_update(&$node) {
   global $user;
 
   // Are email notifications enabled?
-  $email_notifications = variable_get('watcher_email_notifications_enabled', true);
+  $email_notifications = variable_get('watcher_email_notifications_enabled', TRUE);
   if (!$email_notifications) {
-    return false;
+    return FALSE;
   }
 
   // Since a node may be edited by many, we want to exclude the user who just
@@ -1850,15 +1936,15 @@ function _watcher_email_notify_node_update(&$node) {
   $recipients = _watcher_db_get_users_notify_node_update($node->nid, $user->uid);
 
   // Set up subject
-  $node_title = check_plain($node->title ? ' "'. substr($node->title, 0, 128) .'" ' : false);
-  $site_name = variable_get('site_name', false ? ' ('. check_plain(variable_get('site_name', '')) .')' : '');
+  $node_title = check_plain($node->title ? ' "'. substr($node->title, 0, 128) .'" ' : FALSE);
+  $site_name = variable_get('site_name', FALSE ? ' ('. check_plain(variable_get('site_name', '')) .')' : '');
   $subject = t('Post!nodetitlehas been updated!sitename', array('!nodetitle' => $node_title, '!sitename' => $site_name));
 
   // Add to queue
   _watcher_email_notify_node_update_add_to_queue($recipients, $subject, $node);
 
   // Flag that there are messages in queue
-  _watcher_static('messages to send', true);
+  _watcher_static('messages to send', TRUE);
 }
 
 /**
@@ -1895,7 +1981,7 @@ function _watcher_email_notify_node_update_add_to_queue($recipients, $subject, $
     }
 
     // Add to message queue
-    $res = _watcher_email_notifications_add_to_queue($recipient, $subject, $message) && ( isset($res) ? $res : true );
+    $res = _watcher_email_notifications_add_to_queue($recipient, $subject, $message) && ( isset($res) ? $res : TRUE );
   }
   return $res;
 }
@@ -1909,9 +1995,9 @@ function _watcher_email_notify_node_update_add_to_queue($recipients, $subject, $
 function _watcher_email_notify_comment_insert(&$comment) {
 
   // Are email notifications enabled?
-  $email_notifications = variable_get('watcher_email_notifications_enabled', true);
+  $email_notifications = variable_get('watcher_email_notifications_enabled', TRUE);
   if (!$email_notifications) {
-    return false;
+    return FALSE;
   }
 
   // Since a comment is by necessity authored by the current user, we can safely assume
@@ -1928,15 +2014,15 @@ function _watcher_email_notify_comment_insert(&$comment) {
   $node = node_load($comment['nid']);
 
   // Set up subject
-  $node_title = ( $node->title ? t(' about "!nodetitle"', array('!nodetitle' => substr($node->title, 0, 128))) : false );
-  $site_name = ( variable_get('site_name', false ) ? ' ('. variable_get('site_name', '') .')' : '' );
+  $node_title = ( $node->title ? ' '. t('about "!nodetitle"', array('!nodetitle' => substr($node->title, 0, 128))) : FALSE );
+  $site_name = ( variable_get('site_name', FALSE ) ? ' ('. variable_get('site_name', '') .')' : '' );
   $subject = t('New comment posted!aboutnodetitle!sitename', array('!aboutnodetitle' => $node_title, '!sitename' => $site_name));
 
   // Add to queue
   _watcher_email_notify_comment_insert_add_to_queue($recipients, $subject, $comment);
 
   // Flag that there are messages in queue
-  _watcher_static('messages to send', true);
+  _watcher_static('messages to send', TRUE);
 }
 
 /**
@@ -1973,7 +2059,7 @@ function _watcher_email_notify_comment_insert_add_to_queue($recipients, $subject
     }
 
     // Add to message queue
-    $res = _watcher_email_notifications_add_to_queue($recipient, $subject, $message) && ( isset($res) ? $res : true );
+    $res = _watcher_email_notifications_add_to_queue($recipient, $subject, $message) && ( isset($res) ? $res : TRUE );
   }
   return $res;
 }
@@ -1986,12 +2072,12 @@ function _watcher_email_notify_comment_insert_add_to_queue($recipients, $subject
  * @param $nid
  *     NID of node being watched
  */
-function _watcher_email_notify_anonymous_watch_confirm($user, $nid, $what = null) {
+function _watcher_email_notify_anonymous_watch_confirm($user, $nid, $what = NULL) {
 
   // Are email notifications enabled?
-  $email_notifications = variable_get('watcher_email_notifications_enabled', true);
+  $email_notifications = variable_get('watcher_email_notifications_enabled', TRUE);
   if (!$email_notifications) {
-    return false;
+    return FALSE;
   }
 
   // Add user to recipients
@@ -2006,15 +2092,15 @@ function _watcher_email_notify_anonymous_watch_confirm($user, $nid, $what = null
   $subj_for_what['updates'] = ' '. t('for updates');
 
   // Set up subject
-  $node_title = check_plain($node->title ? t(' "!nodetitle"', array('!nodetitle' => substr($node->title, 0, 128))) : false);
-  $site_name = ( variable_get('site_name', false ) ? ' ('. variable_get('site_name', '') .')' : '' );
+  $node_title = check_plain($node->title ? t(' "!nodetitle"', array('!nodetitle' => substr($node->title, 0, 128))) : FALSE);
+  $site_name = ( variable_get('site_name', FALSE ) ? ' ('. variable_get('site_name', '') .')' : '' );
   $subject = t('You are now watching!aboutnodetitle!forwhat!sitename', array('!aboutnodetitle' => $node_title, '!forwhat' => $subj_for_what[$what], '!sitename' => $site_name));
 
   // Add to queue
   _watcher_email_notify_anonymous_watch_confirm_add_to_queue($recipients, $subject, $node);
 
   // Flag that there are messages in queue
-  _watcher_static('messages to send', true);
+  _watcher_static('messages to send', TRUE);
 
 }
 
@@ -2037,7 +2123,7 @@ function _watcher_email_notify_anonymous_watch_confirm_add_to_queue($recipients,
     $message .= _watcher_email_notifications_replace_tokens_header_and_footer($recipient, $node->nid, 'footer_confirm');
 
     // Add to message queue
-    $res = _watcher_email_notifications_add_to_queue($recipient, $subject, $message) && ( isset($res) ? $res : true );
+    $res = _watcher_email_notifications_add_to_queue($recipient, $subject, $message) && ( isset($res) ? $res : TRUE );
   }
   return $res;
 }
@@ -2071,7 +2157,7 @@ function _watcher_user_is_watching_node($user, $nid) {
     if (!isset($result[$uid])) {
       $result[$uid] = _watcher_db_get_nids_by_user($user);
     }
-    return $result[$uid][$nid];
+    return isset($result[$uid][$nid]) ? $result[$uid][$nid] : FALSE;
   }
 
 }
@@ -2087,13 +2173,13 @@ function _watcher_user_is_watching_node($user, $nid) {
  *     A string representing what the user wishes to watch for: all, comments, updates
  *
  * @return
- *     Boolean true on success, false on failure
+ *     Boolean TRUE on success, FALSE on failure
  */
-function _watcher_user_set_watching_node($nid, $user, $what = null) {
+function _watcher_user_set_watching_node($nid, $user, $what = NULL) {
 
   // Check whether this is one of the node types for which Watcher is enabled
   if (!_watcher_node_type_enabled($nid)) {
-    return false;
+    return FALSE;
   }
 
   // For logged-in users, we check if the user is watching the node
@@ -2106,10 +2192,10 @@ function _watcher_user_set_watching_node($nid, $user, $what = null) {
       if (_watcher_user_settings_load('watcher_automatic_enable_notifications') || !$user->uid) {
         _watcher_email_notifications_enable($nid, $user);
       }
-      return true;
+      return TRUE;
     }
   }
-  return false;
+  return FALSE;
 }
 
 /**
@@ -2157,7 +2243,7 @@ function _watcher_user_autowatch_comment_insert($comment) {
 /**
  * Return a link for watching/unwatching a post
  */
-function _watcher_node_watch_link(&$node, $a3, $a4) {
+function _watcher_node_watch_link(&$node, $view_mode) {
 
   global $user;
   $anonymous = !((bool) $user->uid);
@@ -2165,15 +2251,15 @@ function _watcher_node_watch_link(&$node, $a3, $a4) {
   // If email notifications are disabled, no link will be shown to anonymous users
   // as email notifications must be enabled for anonymous users to be notified
   // since they do not have their own binder
-  $email_notifications = variable_get('watcher_email_notifications_enabled', true);
+  $email_notifications = variable_get('watcher_email_notifications_enabled', TRUE);
   if ($anonymous && !$email_notifications) {
     return;
   }
 
   // Do not display toggle watch link in teaser if admin has disabled link for teaser
-  $link_in_teaser = variable_get('watcher_toggle_link_in_teaser', false);
-  if ($a3 && !$link_in_teaser) {
-    return false;
+  $link_in_teaser = variable_get('watcher_toggle_link_in_teaser', FALSE);
+  if ($view_mode == 'teaser' && !$link_in_teaser) {
+    return FALSE;
   }
 
   // Keep track of whether the module has been run multiple times
@@ -2189,7 +2275,8 @@ function _watcher_node_watch_link(&$node, $a3, $a4) {
     $watching = _watcher_user_is_watching_node($user, $node->nid);
   }
 
-  $link_query = drupal_get_destination() ."&token=". _watcher_get_token($node->nid, $user->uid);
+  $link_query = drupal_get_destination();
+  $link_query['token'] = _watcher_get_token($node->nid, $user->uid);
 
   // Make localized strings
   $tstrings = array();
@@ -2213,7 +2300,7 @@ function _watcher_node_watch_link(&$node, $a3, $a4) {
   // strings in our JS settings
   if (!$called) {
     drupal_add_js($settings, 'setting');
-    $called = true;
+    $called = TRUE;
   }
 
   // Add CSS
@@ -2221,7 +2308,7 @@ function _watcher_node_watch_link(&$node, $a3, $a4) {
 
   //Add element to node
   $node->content['watcher'] = array(
-    '#value' => theme('watcher_node_toggle_watching_link', $user->uid, $node->nid, $link_query, $watching, $tstrings),
+    '#markup' => theme('watcher_node_toggle_watching_link', array('uid' => $user->uid, 'nid' => $node->nid, 'query' => $link_query, 'user_is_watching' => $watching, 't' => $tstrings)),
     '#weight' => 30,
   );
 }
@@ -2237,14 +2324,14 @@ function _watcher_node_watch_link(&$node, $a3, $a4) {
  *    A boolean denoting whether the function was called as a result from
  *    the user using the user settings form in their user profile
  */
-function _watcher_user_settings_save($settings, $uid = null) {
+function _watcher_user_settings_save($settings, $uid = NULL) {
   global $user;
 
   // Save to database
   $uid = ( $uid ? $uid : $user->uid );
   if (_watcher_db_set_user_settings($uid, $settings)) {
     drupal_set_message(t('Settings saved.'));
-    return true;
+    return TRUE;
   }
 
 }
@@ -2258,9 +2345,9 @@ function _watcher_user_settings_save($settings, $uid = null) {
  *     The UID of the user account the setting applies to.
  *
  * @return
- *     The setting's value as a string or null.
+ *     The setting's value as a string or NULL.
  */
-function _watcher_user_settings_load($setting, $acct_uid = null) {
+function _watcher_user_settings_load($setting, $acct_uid = NULL) {
   // Include DB dependent functions
   module_load_include('inc', 'watcher', 'watcher.db');
 
@@ -2269,7 +2356,7 @@ function _watcher_user_settings_load($setting, $acct_uid = null) {
 
   // Anonymous users cannot have settings
   if (!$uid) {
-    return false;
+    return FALSE;
   }
 
   // Strip watcher_
@@ -2282,7 +2369,7 @@ function _watcher_user_settings_load($setting, $acct_uid = null) {
 
   // Load from db if setting isn't cached
   if (!isset($settings[$setting])) {
-    $settings = _watcher_db_get_user_settings($uid);
+    $settings = (array) _watcher_db_get_user_settings($uid);
   }
 
   // Return the requested setting
@@ -2296,7 +2383,7 @@ function _watcher_user_settings_load($setting, $acct_uid = null) {
  *   An assoc array of user settings
  *
  */
-function _watcher_user_settings_update_defaults($default_settings = null) {
+function _watcher_user_settings_update_defaults($default_settings = NULL) {
   // Load defaults if not passed as argument
   if (!$default_settings) {
     $default_settings = _watcher_user_settings_load_defaults();
@@ -2315,7 +2402,7 @@ function _watcher_user_settings_update_defaults($default_settings = null) {
  * @return
  *    An associate array of user settings
  */
-function _watcher_user_settings_load_defaults($default_settings = null) {
+function _watcher_user_settings_load_defaults($default_settings = NULL) {
   static $settings;
 
   if (!$settings) {
@@ -2367,7 +2454,7 @@ EOT;
 
 [recipient-username],
 
-Your are receiving this email because you have chosen to receive email notifications from [site-name] ([site-url]). To change this, click the link below to go to your personal settings and disable email notifications:
+Your are receiving this email because you have chosen to receive email notifications from [site:name] ([site:url]). To change this, click the link below to go to your personal settings and disable email notifications:
 [recipient-user-settings-url]
 
 ------------------------------------------
@@ -2388,17 +2475,17 @@ To stop watching this post, click the link below:
 [stop-watching-url]
 
 If you believe you have received this message in error, please contact the site administrator at the following email address:
-[site-mail]
+[site:mail]
 
 Sincerely,
 
-The staff at [site-name] - [site-slogan]
+The staff at [site:name] - [site:slogan]
 
 EOT;
 
 
   // Footer for confirmation messages to anonymous users ////////////////////////
-
+  $templates['footer_confirm'] = '';
   $templates['footer_confirm'] .= <<<EOT
 
 -----------------------------------------
@@ -2412,17 +2499,17 @@ To stop watching ALL posts on this site, click here:
 [stop-watching-all-url]
 
 If you have any further questions, please contact the site administrator at the following email address:
-[site-mail]
+[site:mail]
 
 Sincerely,
 
-The staff at [site-name] - [site-slogan]
+The staff at [site:name] - [site:slogan]
 
 EOT;
 
 
   // Footer for notification messages to anonymous users ////////////////////////
-
+  $templates['footer_anonymous_notify'] = '';
   $templates['footer_anonymous_notify'] .= <<<EOT
 
 -----------------------------------------
@@ -2434,11 +2521,11 @@ To stop watching ALL posts on this site, click here:
 [stop-watching-all-url]
 
 If you have any further questions, please contact the site administrator at the following email address:
-[site-mail]
+[site:mail]
 
 Sincerely,
 
-The staff at [site-name] - [site-slogan]
+The staff at [site:name] - [site:slogan]
 
 EOT;
 
@@ -2448,10 +2535,10 @@ EOT;
   $templates['body_node_update'] = <<<EOT
 
 The following post has been updated:
-[title]
+[node:title]
 
 Click the link below to view it:
-[node-url]
+[node:url]
 
 EOT;
 
@@ -2460,14 +2547,14 @@ EOT;
 
   $templates['body_comment_insert'] = <<<EOT
 
-[comment-author-name] wrote a new comment about '[title]':
-[node-url]
+[comment:author:name] wrote a new comment about '[node:title]':
+[node:url]
 
 Comment excerpt:
 "[comment-excerpt]..."
 
 To read the rest, view the entire comment by clicking the link below:
-[comment-url]
+[comment:url]
 
 Click the link below to reply to this comment:
 [comment-reply-url]
@@ -2479,7 +2566,7 @@ EOT;
   $templates['body_confirm'] = <<<EOT
 
 A request to watch the following page has been made:
-[node-url]
+[node:url]
 
 As long as the page is being watched you will receive email messages when
 new comments or updates are made, depending on what you have chosen to
@@ -2580,15 +2667,15 @@ function _watcher_email_notifications_replace_tokens_node_update($node) {
   $message = variable_get('watcher_notifications_templates_body_node', $templates['body_node_update']) ."\r\n";
 
   // Start by replacing our own tokens
-  $node_url = url('node/'. $node->nid, array('absolute' => true));
+  $node_url = url('node/'. $node->nid, array('absolute' => TRUE));
 
-  $tokens = array('[node-url]');
+  $tokens = array('[node:url]');
   $replaces = array($node_url);
 
   $message = str_replace($tokens, $replaces, $message);
 
   // Replace tokens supplied by Token Module
-  $message = token_replace($message, 'node', $node);
+  $message = token_replace($message, array('node' => $node));
 
   return $message;
 }
@@ -2617,23 +2704,22 @@ function _watcher_email_notifications_replace_tokens_comment_insert($comment) {
   }
 
   // Start by replacing our own tokens
-
   // Load excerpt from cached static
   if (!isset($comment_excerpt)) {
-    $comment_excerpt = _watcher_email_notifications_create_excerpt($comment['comment']);
+    $comment_excerpt = _watcher_email_notifications_create_excerpt($comment['subject']);
   }
-  $comment_url = url('node/'. $comment['nid'], array('fragment' => 'comment-'. $comment['cid'], 'absolute' => true));
-  $comment_reply_url = url('comment/reply/'. $comment['nid'] .'/'. $comment['cid'], array('absolute' => true));
-  $node_url = url('node/'. $comment['nid'], array('absolute' => true));
+  $comment_url = url('node/'. $comment['nid'], array('fragment' => 'comment-'. $comment['cid'], 'absolute' => TRUE));
+  $comment_reply_url = url('comment/reply/'. $comment['nid'] .'/'. $comment['cid'], array('absolute' => TRUE));
+  $node_url = url('node/'. $comment['nid'], array('absolute' => TRUE));
 
-  $tokens = array('[comment-excerpt]', '[comment-url]', '[comment-reply-url]', '[node-url]');
+  $tokens = array('[comment-excerpt]', '[comment:url]', '[comment-reply-url]', '[node:url]');
   $replaces = array($comment_excerpt, $comment_url, $comment_reply_url, $node_url);
 
   $message = str_replace($tokens, $replaces, $message);
 
   // Replace tokens supplied by Token Module
-  $message = token_replace($message, 'comment', $comment);
-  $message = token_replace($message, 'node', $node);
+  $message = token_replace($message, array('comment' => (object) $comment, 'node' => $node));
+//  $message = token_replace($message, 'node', $node);
 
   return $message;
 }
@@ -2650,8 +2736,8 @@ function _watcher_email_notifications_replace_tokens_anonymous_watch_confirm($no
   $message = variable_get('watcher_notifications_templates_body_confirm', $templates['body_confirm']) ."\r\n";
 
   // Start by replacing our own tokens
-  $node_url = url('node/'. $node->nid, array('absolute' => true));
-  $tokens = array('[node-url]');
+  $node_url = url('node/'. $node->nid, array('absolute' => TRUE));
+  $tokens = array('[node:url]');
   $replaces = array($node_url);
   $message = str_replace($tokens, $replaces, $message);
 
@@ -2672,18 +2758,18 @@ function _watcher_email_notifications_replace_tokens_header_and_footer($recipien
   $message = variable_get("watcher_notifications_templates_$type", $templates[$type]);
 
   // Set recipient email address
-  $r_email = ( $recipient->mail ? $recipient->mail : ( $recipient->umail ? $recipient->umail : $recipient->wnmail ));
-
-  $link_query = "token=". _watcher_get_token($nid, $recipient->uid);
+  $r_email = ( isset($recipient->mail) ? $recipient->mail : ( $recipient->umail ? $recipient->umail : $recipient->wnmail ));
+  
+  $link_query['token'] = _watcher_get_token($nid, $recipient->uid);
 
   // Start by replacing our own tokens
   $recipient_username = $recipient->name;
-  $recipient_user_settings_url = url('user/'. $recipient->uid .'/watcher/settings', array('absolute' => true));
-  $stop_watching_url = url('user/'. $recipient->uid .'/watcher/toggle/'. $nid . ( $recipient->uid ? '' : '/unwatch/'. $r_email ), array('absolute' => true, 'query' => $link_query));
-  $stop_watching_all_url = url('user/'. $recipient->uid .'/watcher/toggle/'. $nid .'/unwatch-all/'. $r_email, array('absolute' => true, 'query' => $link_query));
+  $recipient_user_settings_url = url('user/'. $recipient->uid .'/watcher/settings', array('absolute' => TRUE));
+  $stop_watching_url = url('user/'. $recipient->uid .'/watcher/toggle/'. $nid . ( $recipient->uid ? '' : '/unwatch/'. $r_email ), array('absolute' => TRUE, 'query' => $link_query));
+  $stop_watching_all_url = url('user/'. $recipient->uid .'/watcher/toggle/'. $nid .'/unwatch-all/'. $r_email, array('absolute' => TRUE, 'query' => $link_query));
 
   $tokens = array('[recipient-username]', '[recipient-user-settings-url]', '[stop-watching-url]', '[stop-watching-all-url]', '[user-ip]');
-  $replaces = array($recipient_username, $recipient_user_settings_url, $stop_watching_url, $stop_watching_all_url, $recipient->ip);
+  $replaces = array($recipient_username, $recipient_user_settings_url, $stop_watching_url, $stop_watching_all_url, isset($recipient->ip) ? $recipient->ip : '');
 
   $message = str_replace($tokens, $replaces, $message);
 
@@ -2734,7 +2820,7 @@ function _watcher_email_notifications_create_excerpt($text) {
     return (substr($text, 0, $len));
   }
 
-  return null;
+  return NULL;
 
 }
 
@@ -2759,14 +2845,15 @@ function _watcher_node_type_enabled($n) {
     $node = $nodes[$n->nid];
   }
 
+  $res = FALSE;
   if ($node) {
     // Load enabled node types for Watcher
     $enabled_node_types = variable_get('watcher_content_types', array());
 
     // Return match
-    return (bool) $enabled_node_types[$node->type];
+    $res = (bool) $enabled_node_types[$node->type];
   }
-  return false;
+  return $res;
 }
 
 /**
@@ -2783,7 +2870,7 @@ function _watcher_email_notifications_add_to_queue($recipient, $subject, $messag
   // $recipient is an object, obtain variable values
   $r_uid = $recipient->uid;
   // Set mail. Anonymous users have their emails stored in wnmail, registered in umail
-  $r_email = ( $recipient->mail ? $recipient->mail : ( $recipient->umail ? $recipient->umail : $recipient->wnmail ));
+  $r_email = ( isset($recipient->mail) ? $recipient->mail : ( $recipient->umail ? $recipient->umail : $recipient->wnmail ));
 
   // Add to database
   return (_watcher_db_insert_users_notification_queue($r_uid, $r_email, $subject, $message));
@@ -2793,7 +2880,6 @@ function _watcher_email_notifications_add_to_queue($recipient, $subject, $messag
  * Send all messages in queue using the instantaneous method
  */
 function _watcher_email_notifications_send_instant() {
-
   // If there are messages to send, proceed to sending them
   if (_watcher_static('messages to send')) {
     $method = variable_get('watcher_email_notifications_method', 'cron');
@@ -2825,11 +2911,12 @@ function _watcher_email_notifications_send_queue() {
   // Normally, we should have an array of notifications but let's check
   // just to be sure
   if (is_array($qmsgs)) {
-
+    $sent_qmsgs = array();
+    
     // Start the timer
-    _watcher_email_notifications_send_queue_timer(true);
+    _watcher_email_notifications_send_queue_timer(TRUE);
 
-    // Process queue until timer says stop (returns false) or we run out of notifications
+    // Process queue until timer says stop (returns FALSE) or we run out of notifications
     while ((list($k, $qmsg) = each($qmsgs)) && _watcher_email_notifications_send_queue_timer()) {
 
       // Send message and add it to the sent messages array
@@ -2866,9 +2953,9 @@ function _watcher_email_notifications_send_queue() {
  *    A boolean denoting that the timer should start
  *
  * @return
- *    A boolean true if the time limit hasn't expired, a false if it has
+ *    A boolean TRUE if the time limit hasn't expired, a FALSE if it has
  */
-function _watcher_email_notifications_send_queue_timer($start = false) {
+function _watcher_email_notifications_send_queue_timer($start = FALSE) {
   // Store current time in a static var
   static $start_time;
   static $time_limit;
@@ -2885,7 +2972,7 @@ function _watcher_email_notifications_send_queue_timer($start = false) {
   }
 
   // Get current time in seconds and microseconds
-  list($msec, $sec) = explode(" ", microtime(true));
+  list($msec, $sec) = explode(' ', microtime());
   $cur_time = ((float)$msec + (float)$sec);
 
   // We're starting, set starting time
@@ -2935,13 +3022,13 @@ function _watcher_email_notifications_send_message($qmsg) {
 
   // Set up params
   $params['subject'] = $subject;
-  $params['body'] = $body;
+  $params['body'] = array($body);
 
   // Language
   $language = language_default();
 
   // Send email
-  $message = drupal_mail('watcher', 'notification', $to, $language, $params, $from, true);
+  $message = drupal_mail('watcher', 'notification', $to, $language, $params, $from, TRUE);
 
   return $message['result'];
 
@@ -2958,7 +3045,7 @@ function _watcher_email_notifications_send_message($qmsg) {
  * @return
  *     A FAPI form array
  */
-function _watcher_watch_toggle_anonymous_form(&$form_state, $nid, $watch_action){
+function _watcher_watch_toggle_anonymous_form($form, &$form_submit, $nid, $watch_action) {
 
   // Load previous entered form details from current session
   $mail = _watcher_session('mail');
@@ -2971,7 +3058,7 @@ function _watcher_watch_toggle_anonymous_form(&$form_state, $nid, $watch_action)
   $message = variable_get("watcher_notifications_templates_$type", $templates['footer_confirm']);
 
   // Determine if user's IP address token is included in template
-  $ip_reported = (strpos($message, '[user-ip]') !== false);
+  $ip_reported = (strpos($message, '[user-ip]') !== FALSE);
 
   // Messages
   $ip_info = ' '. t("The confirmation message contains your IP address so that in case of abuse the owner of the email account can identify who submitted the form.");
@@ -2980,22 +3067,22 @@ function _watcher_watch_toggle_anonymous_form(&$form_state, $nid, $watch_action)
 
   // Help text depending on watch action
   if ($watch_action == 'unwatch') {
-    $form['watcher'] = array (
+    $form['watcher'] = array(
       '#type' => 'fieldset',
       '#title' => '<strong>'. t("Stop watching %title", array('%title' => check_plain($node->title))) .'</strong>',
     );
-    $info = t("Enter your email address below to stop watching %title. The form will remember the email you enter until next time.", array('%title' => check_plain($node->title), '%ipinfo' => ( $ip_reported ? $ip_info : null )));
+    $info = t("Enter your email address below to stop watching %title. The form will remember the email you enter until next time.", array('%title' => check_plain($node->title), '%ipinfo' => ( $ip_reported ? $ip_info : NULL )));
   }
   else {
-    $form['watcher'] = array (
+    $form['watcher'] = array(
       '#type' => 'fieldset',
       '#title' => '<strong>'. t("Watch %title", array('%title' => check_plain($node->title))) .'</strong>',
     );
-    $info = t("Enter your email address below to start watching %title. The form will remember the email you enter until next time. Once you submit the form, a confirmation message will be sent to the email address entered. %ipinfo", array('%title' => $node->title, '%ipinfo' => ( $ip_reported ? $ip_info : null )));
+    $info = t("Enter your email address below to start watching %title. The form will remember the email you enter until next time. Once you submit the form, a confirmation message will be sent to the email address entered. %ipinfo", array('%title' => check_plain($node->title), '%ipinfo' => ( $ip_reported ? $ip_info : NULL )));
   }
 
   $form['watcher'][] = array(
-    '#value' => $info,
+    '#markup' => $info,
     '#weight' => 0,
   );
 
@@ -3005,7 +3092,7 @@ function _watcher_watch_toggle_anonymous_form(&$form_state, $nid, $watch_action)
     '#default_value' => $mail,
     '#size' => 32,
     '#maxlength' => 128,
-    '#required' => true,
+    '#required' => TRUE,
     '#weight' => 5,
   );
 
@@ -3021,7 +3108,7 @@ function _watcher_watch_toggle_anonymous_form(&$form_state, $nid, $watch_action)
     ),
       '#default_value' => $what,
       '#description' => t('Choose to be informed about new comments, updates (this post being changed) or both.'),
-      '#required' => true,
+      '#required' => TRUE,
       '#weight' => 10,
     );
   }
@@ -3055,9 +3142,9 @@ function _watcher_watch_toggle_anonymous_form(&$form_state, $nid, $watch_action)
  * @return
  *     If $value is not passed, the value stored for $name is returned
  */
-function _watcher_static($name, $value = null) {
+function _watcher_static($name, $value = NULL) {
   static $static;
-  if (is_null($value)) {
+  if (is_NULL($value)) {
     return $static[$name];
   }
   $static[$name] = $value;
@@ -3086,7 +3173,7 @@ function _watcher_filter_rfc2047_especials($string) {
  * @return
  *     If only $key is given, sought-after value for key
  */
-function _watcher_session($key, $value = null) {
+function _watcher_session($key, $value = NULL) {
   if (isset($value)) {
     unset($_SESSION[$key]);
     $_SESSION[$key] = $value;
@@ -3110,7 +3197,7 @@ function _watcher_session($key, $value = null) {
  * @param $form_state
  *     A form state array
  */
-function _watcher_user_settings_submit($form, &$form_state) {
+function _watcher_user_settings_submit($form, $form_state) {
 
   // Extract settings
   foreach ($form_state['values'] as $key => $item) {
@@ -3131,7 +3218,7 @@ function _watcher_user_settings_submit($form, &$form_state) {
  * @param $form_state
  *     A form state array
  */
-function _watcher_watch_toggle_anonymous_form_submit($form, &$form_state) {
+function _watcher_watch_toggle_anonymous_form_submit($form, $form_state) {
   global $user;
   $nid = $form_state['values']['nid'];
   $what = $form_state['values']['what'];
@@ -3201,8 +3288,8 @@ function _watcher_watch_toggle_anonymous_form_submit($form, &$form_state) {
 /**
  * Get a private token used to protect links from spoofing - CSRF.
  */
-function _watcher_get_token($seed, $uid = false) {
-  if ($uid === false) {
+function _watcher_get_token($seed, $uid = FALSE) {
+  if ($uid === FALSE) {
     $uid = $GLOBALS['user']->uid;
   }
   return drupal_get_token($seed . $uid);
@@ -3211,9 +3298,9 @@ function _watcher_get_token($seed, $uid = false) {
 /**
  * Check to see if a token value matches the specified node.
  */
-function _watcher_check_token($token, $seed, $uid = false) {
-  if ($uid === false) {
-    $uid =  $GLOBALS['user']->uid;
+function _watcher_check_token($token, $seed, $uid = FALSE) {
+  if ($uid === FALSE) {
+    $uid = $GLOBALS['user']->uid;
   }
   return drupal_get_token($seed . $uid) == $token;
 }
@@ -3230,7 +3317,7 @@ function _watcher_check_token($token, $seed, $uid = false) {
  * @param $form_state
  *     Populated form with values
  */
-function _watcher_watch_toggle_anonymous_form_validate($form, &$form_state) {
+function _watcher_watch_toggle_anonymous_form_validate($form, $form_state) {
   if (!valid_email_address(trim($form_state['values']['mail']))) {
     form_set_error('mail', t('You must enter a valid e-mail address.'));
   }
