diff --git a/dmemcache.inc b/dmemcache.inc
index 63af64d..5974c33 100644
--- a/dmemcache.inc
+++ b/dmemcache.inc
@@ -1,17 +1,17 @@
 <?php
 
-/*
- * Core dmemcache functions required by:
+/**
+ * @file
  *   memcache.inc
+ * Core dmemcache functions required by:
  *   memcache.db.inc
- *   session-memcache.inc
- *   session-memcache.db.inc
+ *   memcache-session.inc
  */
 
 global $_dmemcache_stats;
 $_dmemcache_stats = array('all' => array(), 'ops' => array());
 
-/*
+/**
  * A memcache API for Drupal.
  */
 
@@ -55,25 +55,32 @@ function dmemcache_set($key, $value, $exp = 0, $bin = 'cache', $mc = NULL) {
 }
 
 /**
- *  Add an item into memcache
+ * Add an item into memcache.
  *
- * @param $key The string with which you will retrieve this item later.
- * @param $value The item to be stored.
- * @param $exp Parameter expire is expiration time in seconds. If it's 0, the
+ * @param string $key
+ *   The string with which you will retrieve this item later.
+ * @param mixed $value
+ *   The item to be stored.
+ * @param int $exp
+ *   Parameter expire is expiration time in seconds. If it's 0, the
  *   item never expires (but memcached server doesn't guarantee this item to be
  *   stored all the time, it could be deleted from the cache to make place for
  *   other items).
- * @param $bin The name of the Drupal subsystem that is making this call.
+ * @param string $bin
+ *   The name of the Drupal subsystem that is making this call.
  *   Examples could be 'cache', 'alias', 'taxonomy term' etc. It is possible
  *   to map different $bin values to different memcache servers.
- * @param $mc Optionally pass in the memcache object.  Normally this value is
+ * @param object $mc
+ *   Optionally pass in the memcache object.  Normally this value is
  *   determined automatically based on the bin the object is being stored to.
- * @param $flag If using the older memcache PECL extension as opposed to the
+ * @param int $flag
+ *   If using the older memcache PECL extension as opposed to the
  *   newer memcached PECL extension, the MEMCACHE_COMPRESSED flag can be set
  *   to use zlib to store a compressed copy of the item.  This flag option is
  *   completely ignored when using the newer memcached PECL extension.
  *
  * @return bool
+ *   FALSE if placing the item into memcache failed.
  */
 function dmemcache_add($key, $value, $exp = 0, $bin = 'cache', $mc = NULL, $flag = FALSE) {
   $collect_stats = dmemcache_stats_init();
@@ -100,10 +107,13 @@ function dmemcache_add($key, $value, $exp = 0, $bin = 'cache', $mc = NULL, $flag
 /**
  * Retrieve a value from the cache.
  *
- * @param $key The key with which the item was stored.
- * @param $bin The bin in which the item was stored.
+ * @param string $key
+ *   The key with which the item was stored.
+ * @param string $bin
+ *   The bin in which the item was stored.
  *
- * @return The item which was originally saved or FALSE
+ * @return mixed
+ *   The item which was originally saved or FALSE
  */
 function dmemcache_get($key, $bin = 'cache', $mc = NULL) {
   $collect_stats = dmemcache_stats_init();
@@ -135,10 +145,13 @@ function dmemcache_get($key, $bin = 'cache', $mc = NULL) {
 /**
  * Retrieve multiple values from the cache.
  *
- * @param $keys The keys with which the items were stored.
- * @param $bin The bin in which the item was stored.
+ * @param array $keys
+ *   The keys with which the items were stored.
+ * @param string $bin
+ *   The bin in which the item was stored.
  *
- * @return The item which was originally saved or FALSE
+ * @return mixed
+ *   The item which was originally saved or FALSE
  */
 function dmemcache_get_multi($keys, $bin = 'cache', $mc = NULL) {
   $collect_stats = dmemcache_stats_init();
@@ -201,10 +214,13 @@ function dmemcache_get_multi($keys, $bin = 'cache', $mc = NULL) {
 /**
  * Deletes an item from the cache.
  *
- * @param $key The key with which the item was stored.
- * @param $bin The bin in which the item was stored.
+ * @param string $key
+ *   The key with which the item was stored.
+ * @param string $bin
+ *   The bin in which the item was stored.
  *
- * @return Returns TRUE on success or FALSE on failure.
+ * @return bool
+ *   Returns TRUE on success or FALSE on failure.
  */
 function dmemcache_delete($key, $bin = 'cache', $mc = NULL) {
   $collect_stats = dmemcache_stats_init();
@@ -224,14 +240,18 @@ function dmemcache_delete($key, $bin = 'cache', $mc = NULL) {
 }
 
 /**
- * Immediately invalidates all existing items. dmemcache_flush doesn't actually free any
- * resources, it only marks all the items as expired, so occupied memory will be overwritten by
- * new items.
+ * Flush all stored items.
+ *
+ * Immediately invalidates all existing items. dmemcache_flush doesn't actually
+ * free any resources, it only marks all the items as expired, so occupied
+ * memory will be overwritten by new items.
  *
- * @param $bin The bin to flush. Note that this will flush all bins mapped to the same server
- *   as $bin. There is no way at this time to empty just one bin.
+ * @param string $bin
+ *   The bin to flush. Note that this will flush all bins mapped to the same
+ *   server as $bin. There is no way at this time to empty just one bin.
  *
- * @return Returns TRUE on success or FALSE on failure.
+ * @return bool
+ *   Returns TRUE on success or FALSE on failure.
  */
 function dmemcache_flush($bin = 'cache', $mc = NULL) {
   $collect_stats = dmemcache_stats_init();
@@ -251,11 +271,21 @@ function dmemcache_flush($bin = 'cache', $mc = NULL) {
   return $rc;
 }
 
+/**
+ * Retrieves statistics recorded during memcache operations.
+ *
+ * @param string $stats_bin
+ *   The bin to retrieve statistics for.
+ * @param string $stats_type
+ *   The type of statistics to retrieve when using the Memcache extension.
+ * @param bool $aggregate
+ *   Whether to aggregate statistics.
+ */
 function dmemcache_stats($stats_bin = 'cache', $stats_type = 'default', $aggregate = FALSE) {
   $memcache_bins = variable_get('memcache_bins', array('cache' => 'default'));
   // The stats_type can be over-loaded with an integer slab id, if doing a
   // cachedump.  We know we're doing a cachedump if $slab is non-zero.
-  $slab = (int)$stats_type;
+  $slab = (int) $stats_type;
 
   foreach ($memcache_bins as $bin => $target) {
     if ($stats_bin == $bin) {
@@ -267,13 +297,13 @@ function dmemcache_stats($stats_bin = 'cache', $stats_type = 'default', $aggrega
         // type is NULL or not in {reset, malloc, slabs, cachedump, items,
         // sizes}. If $stats_type is 'default', then no parameter should be
         // passed to the Memcache memcache_get_extended_stats() function.
-        else if ($mc instanceof Memcache) {
+        elseif ($mc instanceof Memcache) {
           if ($stats_type == 'default' || $stats_type == '') {
             $stats[$bin] = $mc->getExtendedStats();
           }
           // If $slab isn't zero, then we are dumping the contents of a
           // specific cache slab.
-          else if (!empty($slab))  {
+          elseif (!empty($slab)) {
             $stats[$bin] = $mc->getStats('cachedump', $slab);
           }
           else {
@@ -286,8 +316,15 @@ function dmemcache_stats($stats_bin = 'cache', $stats_type = 'default', $aggrega
   // Optionally calculate a sum-total for all servers in the current bin.
   if ($aggregate) {
     // Some variables don't logically aggregate.
-    $no_aggregate = array('pid', 'time', 'version', 'pointer_size', 'accepting_conns', 'listen_disabled_num');
-    foreach($stats as $bin => $servers) {
+    $no_aggregate = array(
+      'pid',
+      'time',
+      'version',
+      'pointer_size',
+      'accepting_conns',
+      'listen_disabled_num',
+    );
+    foreach ($stats as $bin => $servers) {
       if (is_array($servers)) {
         foreach ($servers as $server) {
           if (is_array($server)) {
@@ -432,7 +469,7 @@ function dmemcache_connect($memcache, $server, $connection) {
       $rc = $memcache->addServer($host, $port, $memcache_persistent);
     }
   }
-  else if ($extension == 'Memcached') {
+  elseif ($extension == 'Memcached') {
     // Support unix sockets of the format 'unix:///path/to/socket'.
     if ($host == 'unix') {
       // Strip 'unix://' as expected by Memcached extension.
@@ -455,7 +492,7 @@ function dmemcache_close($memcache) {
   if ($extension == 'Memcache' && $memcache instanceof Memcache) {
     $rc = @$memcache->close;
   }
-  else if ($extension == 'Memcached' && $memcache instanceof Memcached) {
+  elseif ($extension == 'Memcached' && $memcache instanceof Memcached) {
     $rc = @$memcache->quit;
   }
   else {
@@ -479,21 +516,21 @@ function dmemcache_close($memcache) {
  * @return a Memcache object or FALSE.
  */
 function dmemcache_object($bin = NULL, $flush = FALSE) {
-  static $memcacheCache = array();
+  static $memcache_cache = array();
   static $memcache_servers = array();
   static $memcache_bins = array();
   static $failed_connections = array();
 
   if ($flush) {
-    foreach ($memcacheCache as $cluster) {
+    foreach ($memcache_cache as $cluster) {
       memcache_close($cluster);
     }
-    $memcacheCache = array();
+    $memcache_cache = array();
   }
 
   $extension = dmemcache_extension();
 
-  if (empty($memcacheCache) || empty($memcacheCache[$bin])) {
+  if (empty($memcache_cache) || empty($memcache_cache[$bin])) {
     if (empty($memcache_servers)) {
       // Load the variables from settings.php if set.
       $memcache_servers = variable_get('memcache_servers', array('127.0.0.1:11211' => 'default'));
@@ -505,8 +542,8 @@ function dmemcache_object($bin = NULL, $flush = FALSE) {
 
     // If not manually set, map this bin to 'cache' which maps to the 'default'
     // cluster.
-    if (empty($memcache_bins[$bin]) && !empty($memcacheCache['cache'])) {
-      $memcacheCache[$bin] = &$memcacheCache['cache'];
+    if (empty($memcache_bins[$bin]) && !empty($memcache_cache['cache'])) {
+      $memcache_cache[$bin] = &$memcache_cache['cache'];
     }
     else {
       // Create a new memcache object for each cluster.
@@ -535,23 +572,34 @@ function dmemcache_object($bin = NULL, $flush = FALSE) {
       }
       if ($connection) {
         // Map the current bin with the new Memcache object.
-        $memcacheCache[$bin] = $memcache;
+        $memcache_cache[$bin] = $memcache;
 
         // Now that all the servers have been mapped to this cluster, look for
         // other bins that belong to the cluster and map them too.
         foreach ($memcache_bins as $b => $c) {
           if ($c == $cluster && $b != $bin) {
             // Map this bin and cluster by reference.
-            $memcacheCache[$b] = &$memcacheCache[$bin];
+            $memcache_cache[$b] = &$memcache_cache[$bin];
           }
         }
       }
     }
   }
 
-  return empty($memcacheCache[$bin]) ? FALSE : $memcacheCache[$bin];
+  return empty($memcache_cache[$bin]) ? FALSE : $memcache_cache[$bin];
 }
 
+/**
+ * Prefixes a key and ensures it is url safe.
+ *
+ * @param string $key
+ *   The key to prefix and encode.
+ * @param string $bin
+ *   The cache bin which the key applies to.
+ *
+ * @return string
+ *   The prefixed and encoded key.
+ */
 function dmemcache_key($key, $bin = 'cache') {
   $prefix = '';
   if ($prefix = variable_get('memcache_key_prefix', '')) {
diff --git a/memcache-lock-code.inc b/memcache-lock-code.inc
index 15e3283..fbf459e 100644
--- a/memcache-lock-code.inc
+++ b/memcache-lock-code.inc
@@ -21,11 +21,12 @@ function lock_initialize() {
 /**
  * Acquire (or renew) a lock, but do not block if it fails.
  *
- * @param $name
+ * @param string $name
  *   The name of the lock.
- * @param $timeout
+ * @param int $timeout
  *   A number of seconds (int) before the lock expires (minimum of 1).
- * @return
+ *
+ * @return bool
  *   TRUE if the lock was acquired, FALSE if it failed.
  */
 function lock_acquire($name, $timeout = 30) {
@@ -56,9 +57,10 @@ function lock_acquire($name, $timeout = 30) {
  *
  * If an existing lock has expired, it is removed.
  *
- * @param $name
+ * @param string $name
  *   The name of the lock.
- * @return
+ *
+ * @return bool
  *   TRUE if there is no lock or it was removed, FALSE otherwise.
  */
 function lock_may_be_available($name) {
@@ -74,23 +76,26 @@ function lock_may_be_available($name) {
  * that are acquired very frequently, since the lock is likely to be acquired
  * again by a different request while waiting.
  *
- * @param $name
+ * @param string $name
  *   The name of the lock.
- * @param $delay
+ * @param int $delay
  *   The maximum number of seconds to wait, as an integer.
- * @return
+ *
+ * @return bool
  *   TRUE if the lock holds, FALSE if it is available.
  */
 function lock_wait($name, $delay = 30) {
-  // Pause the process for short periods between calling
-  // lock_may_be_available(). This prevents hitting the database with constant
-  // database queries while waiting, which could lead to performance issues.
-  // However, if the wait period is too long, there is the potential for a
-  // large number of processes to be blocked waiting for a lock, especially
-  // if the item being rebuilt is commonly requested. To address both of these
-  // concerns, begin waiting for 25ms, then add 25ms to the wait period each
-  // time until it reaches 500ms. After this point polling will continue every
-  // 500ms until $delay is reached.
+  /*
+   * Pause the process for short periods between calling
+   * lock_may_be_available(). This prevents hitting the database with constant
+   * database queries while waiting, which could lead to performance issues.
+   * However, if the wait period is too long, there is the potential for a
+   * large number of processes to be blocked waiting for a lock, especially
+   * if the item being rebuilt is commonly requested. To address both of these
+   * concerns, begin waiting for 25ms, then add 25ms to the wait period each
+   * time until it reaches 500ms. After this point polling will continue every
+   * 500ms until $delay is reached.
+   */
 
   // $delay is passed in seconds, but we will be using usleep(), which takes
   // microseconds as a parameter. Multiply it by 1 million so that all
@@ -122,7 +127,7 @@ function lock_wait($name, $delay = 30) {
  *
  * This will release the named lock if it is still held by the current request.
  *
- * @param $name
+ * @param string $name
  *   The name of the lock.
  */
 function lock_release($name) {
diff --git a/memcache-lock.inc b/memcache-lock.inc
index bc0f936..ef176df 100644
--- a/memcache-lock.inc
+++ b/memcache-lock.inc
@@ -15,4 +15,4 @@ $lock_file = dirname(__FILE__) . '/memcache-lock-code.inc';
 if (!dmemcache_object('semaphore')) {
   $lock_file = DRUPAL_ROOT . '/includes/lock.inc';
 }
-require_once $lock_file;
\ No newline at end of file
+require_once $lock_file;
diff --git a/memcache.inc b/memcache.inc
index 41b6bf4..64292d3 100644
--- a/memcache.inc
+++ b/memcache.inc
@@ -1,17 +1,30 @@
 <?php
 
+/**
+ * @file
+ * Implementation of cache.inc with memcache logic included.
+ */
+
 require_once dirname(__FILE__) . '/dmemcache.inc';
 
 /**
  * Defines the period after which wildcard clears are not considered valid.
  */
 define('MEMCACHE_WILDCARD_INVALIDATE', 86400 * 28);
-
 define('MEMCACHE_CONTENT_CLEAR', 'MEMCACHE_CONTENT_CLEAR');
 
-/** Implementation of cache.inc with memcache logic included **/
-
+/**
+ * Implementation of cache.inc with memcache logic included
+ */
 class MemCacheDrupal implements DrupalCacheInterface {
+  protected $memcache;
+
+  /**
+   * Constructs a MemCacheDrupal object.
+   *
+   * @param $bin
+   *   The cache bin for which the object is created.
+   */
   function __construct($bin) {
     $this->memcache = dmemcache_object($bin);
     $this->bin = $bin;
@@ -40,11 +53,17 @@ class MemCacheDrupal implements DrupalCacheInterface {
     $this->reloadVariables();
   }
 
+  /**
+   * Implements DrupalCacheInterface::get().
+   */
   function get($cid) {
     $cache = dmemcache_get($cid, $this->bin, $this->memcache);
     return $this->valid($cid, $cache) ? $cache : FALSE;
   }
 
+  /**
+   * Implements DrupalCacheInterface::getMultiple().
+   */
   function getMultiple(&$cids) {
     $results = dmemcache_get_multi($cids, $this->bin, $this->memcache);
     foreach ($results as $cid => $result) {
@@ -59,15 +78,26 @@ class MemCacheDrupal implements DrupalCacheInterface {
     return $results;
   }
 
+  /**
+   * Checks if a retrieved cache item is valid.
+   *
+   * @param string $cid
+   *   The cache id of the item
+   * @param mixed $cache
+   *   The cache item.
+   *
+   * @return bool
+   *   Whether the item is valid.
+   */
   protected function valid($cid, $cache) {
     if ($cache) {
       $cache_tables = isset($_SESSION['cache_flush']) ? $_SESSION['cache_flush'] : NULL;
       // Items that have expired are invalid.
       if (isset($cache->expire) && $cache->expire !== CACHE_PERMANENT && $cache->expire <= $_SERVER['REQUEST_TIME']) {
-        // If the memcache_stampede_protection variable is set, allow one process
-        // to rebuild the cache entry while serving expired content to the
-        // rest. Note that core happily returns expired cache items as valid and
-        // relies on cron to expire them, but this is mostly reliant on its
+        // If the memcache_stampede_protection variable is set, allow one
+        // process to rebuild the cache entry while serving expired content to
+        // the rest. Note that core happily returns expired cache items as valid
+        // and relies on cron to expire them, but this is mostly reliant on its
         // use of CACHE_TEMPORARY which does not map well to memcache.
         // @see http://drupal.org/node/534092
         if (variable_get('memcache_stampede_protection', FALSE)) {
@@ -105,7 +135,7 @@ class MemCacheDrupal implements DrupalCacheInterface {
       }
       // Finally, check for wildcard clears against this cid.
       else {
-        if (!$this->wildcard_valid($cid, $cache)) {
+        if (!$this->wildcardValid($cid, $cache)) {
           $cache = FALSE;
         }
       }
@@ -127,9 +157,9 @@ class MemCacheDrupal implements DrupalCacheInterface {
         static $lock_count = 0;
         $lock_count++;
         if ($lock_count <= variable_get('memcache_stampede_wait_limit', 3)) {
-          // The memcache_stampede_semaphore variable was used in previous releases
-          // of memcache, but the max_wait variable was not, so by default divide
-          // the semaphore value by 3 (5 seconds).
+          // The memcache_stampede_semaphore variable was used in previous
+          // releases of memcache, but the max_wait variable was not, so by
+          // default divide the semaphore value by 3 (5 seconds).
           lock_wait("memcache_$cid:$this->bin", variable_get('memcache_stampede_wait_time', 5));
           $cache = $this->get($cid);
         }
@@ -139,6 +169,9 @@ class MemCacheDrupal implements DrupalCacheInterface {
     return (bool) $cache;
   }
 
+  /**
+   * Implements DrupalCacheInterface::set().
+   */
   function set($cid, $data, $expire = CACHE_PERMANENT) {
     $created = time();
 
@@ -157,7 +190,7 @@ class MemCacheDrupal implements DrupalCacheInterface {
       $cache->temporary = TRUE;
     }
     // Expire time is in seconds if less than 30 days, otherwise is a timestamp.
-    else if ($expire != CACHE_PERMANENT && $expire < 2592000) {
+    elseif ($expire != CACHE_PERMANENT && $expire < 2592000) {
       // Expire is expressed in seconds, convert to the proper future timestamp
       // as expected in dmemcache_get().
       $cache->expire = REQUEST_TIME + $expire;
@@ -189,7 +222,10 @@ class MemCacheDrupal implements DrupalCacheInterface {
     }
   }
 
-  function clear($cid = NULL, $wildcard = FALSE) {
+  /**
+   * Implements DrupalCacheInterface::clear().
+   */
+  public function clear($cid = NULL, $wildcard = FALSE) {
     if ($this->memcache === FALSE) {
       // No memcache connection.
       return;
@@ -248,9 +284,9 @@ class MemCacheDrupal implements DrupalCacheInterface {
 
         if ($this->cache_lifetime) {
           // We store the time in the current user's session which is saved into
-          // the sessions table by sess_write().  We then simulate that the cache
-          // was flushed for this user by not returning cached data to this user
-          // that was cached before the timestamp.
+          // the sessions table by sess_write().  We then simulate that the
+          // cache was flushed for this user by not returning cached data to
+          // this user that was cached before the timestamp.
           if (isset($_SESSION['cache_flush']) && is_array($_SESSION['cache_flush'])) {
             $cache_bins = $_SESSION['cache_flush'];
           }
@@ -262,7 +298,7 @@ class MemCacheDrupal implements DrupalCacheInterface {
         }
       }
       else {
-        // Register a wildcard flush for current cid
+        // Register a wildcard flush for current cid.
         $this->wildcards($cid, TRUE);
       }
     }
@@ -275,15 +311,24 @@ class MemCacheDrupal implements DrupalCacheInterface {
   }
 
   /**
-   * Sum of all matching wildcards.  Checking any single cache item's flush
-   * value against this single-value sum tells us whether or not a new wildcard
-   * flush has affected the cached item.
+   * Sum of all matching wildcards.
+   *
+   * Checking any single cache item's flush value against this single-value sum
+   * tells us whether or not a new wildcard flush has affected the cached item.
+   *
+   * @param string $cid
+   *   The cache id to check.
+   *
+   * @return int
+   *   Sum of all matching wildcards for the given cache id.
    */
   protected function wildcard_flushes($cid) {
     return array_sum($this->wildcards($cid));
   }
 
   /**
+   * Retrieves all matching wildcards for the given cache id.
+   *
    * Utilize multiget to retrieve all possible wildcard matches, storing
    * statically so multiple cache requests for the same item on the same page
    * load doesn't add overhead.
@@ -398,17 +443,20 @@ class MemCacheDrupal implements DrupalCacheInterface {
   /**
    * Check if a wildcard flush has invalidated the current cached copy.
    */
-  protected function wildcard_valid($cid, $cache) {
+  protected function wildcardValid($cid, $cache) {
     // Previously cached content won't have ->flushes defined.  We could
     // force flush, but instead leave this up to the site admin.
-    $flushes = isset($cache->flushes) ? (int)$cache->flushes : 0;
-    if ($flushes < (int)$this->wildcard_flushes($cid)) {
+    $flushes = isset($cache->flushes) ? (int) $cache->flushes : 0;
+    if ($flushes < (int) $this->wildcard_flushes($cid)) {
       return FALSE;
     }
     return TRUE;
   }
 
-  function isEmpty() {
+  /**
+   * Implements DrupalCacheInterface::isEmpty().
+   */
+  public function isEmpty() {
     // We do not know so err on the safe side?
     return FALSE;
   }
@@ -431,7 +479,7 @@ class MemCacheDrupal implements DrupalCacheInterface {
    * This is used by the tests to verify that the cache object used the correct
    * settings.
    */
-  function reloadVariables() {
+  public function reloadVariables() {
     $this->wildcard_flushes = variable_get('memcache_wildcard_flushes', array());
     $this->invalidate = variable_get('memcache_wildcard_invalidate', MEMCACHE_WILDCARD_INVALIDATE);
     $this->cache_lifetime = variable_get('cache_lifetime', 0);
@@ -444,7 +492,7 @@ class MemCacheDrupal implements DrupalCacheInterface {
   /**
    * Re-implementation of variable_set() that writes through instead of clearing.
    */
-  function variable_set($name, $value) {
+  public function variable_set($name, $value) {
     global $conf;
 
     db_merge('variable')
diff --git a/memcache.info b/memcache.info
index 9a36645..5d6d493 100644
--- a/memcache.info
+++ b/memcache.info
@@ -2,6 +2,7 @@ name = Memcache
 description = High performance integration with memcache.
 package = Performance and scalability
 core = 7.x
+files[] = memcache.inc
 files[] = tests/memcache.test
 files[] = tests/memcache-session.test
 files[] = tests/memcache-lock.test
diff --git a/memcache.install b/memcache.install
index a5e4825..233e39c 100644
--- a/memcache.install
+++ b/memcache.install
@@ -1,6 +1,11 @@
 <?php
 
 /**
+ * @file
+ * Install, update and uninstall functions for the memcache module.
+ */
+
+/**
  * Implements hook_requirements().
  */
 function memcache_requirements($phase) {
@@ -30,7 +35,7 @@ function memcache_requirements($phase) {
       if ($extension == 'Memcache') {
         $requirements['memcache_extension']['value'] = phpversion('memcache') . _memcache_statistics_link();
       }
-      else if ($extension == 'Memcached') {
+      elseif ($extension == 'Memcached') {
         $requirements['memcache_extension']['value'] = phpversion('memcached') . _memcache_statistics_link();
       }
 
diff --git a/memcache.module b/memcache.module
index f70a91b..aeefd21 100644
--- a/memcache.module
+++ b/memcache.module
@@ -1,5 +1,7 @@
 <?php
+
 /**
+ * @file
  * Provides very limited functionality such as hook_requirements().
  * memcache.inc must be configured in settings.php, and memcache.module is not
  * necessary to use memcache as a cache backend.
@@ -29,6 +31,6 @@ function memcache_enable() {
     }
   }
   if ($error) {
-    drupal_set_message(t('There are problems with your Memcache configuration. Please review %readme and visit the Drupal admin !status page for more information.', array('%readme' => 'README.txt', '!status' => l('status report', 'admin/reports/status'))), 'error');
+    drupal_set_message(t('There are problems with your Memcache configuration. Please review %readme and visit the Drupal admin !status page for more information.', array('%readme' => 'README.txt', '!status' => l(t('status report'), 'admin/reports/status'))), 'error');
   }
 }
diff --git a/memcache_admin/memcache.js b/memcache_admin/memcache.js
index c6b79a0..c28fbf5 100644
--- a/memcache_admin/memcache.js
+++ b/memcache_admin/memcache.js
@@ -1,7 +1,11 @@
+/**
+ * @file
+ * Helper functions for memcache_admin module.
+ */
 
 // Global Killswitch
 if (Drupal.jsEnabled) {
-$(document).ready(function() {
+  $(document).ready(function() {
     $("body").append($("#memcache-devel"));
   });
 }
diff --git a/memcache_admin/memcache_admin.install b/memcache_admin/memcache_admin.install
index 0f2652e..7c5c711 100644
--- a/memcache_admin/memcache_admin.install
+++ b/memcache_admin/memcache_admin.install
@@ -1,7 +1,8 @@
 <?php
 
 /**
- * @file update functions for memcache_admin.
+ * @file
+ * Update functions for memcache_admin.
  */
 
 /**
diff --git a/memcache_admin/memcache_admin.module b/memcache_admin/memcache_admin.module
index 3d78e36..c9ea392 100644
--- a/memcache_admin/memcache_admin.module
+++ b/memcache_admin/memcache_admin.module
@@ -1,6 +1,7 @@
 <?php
 
 /**
+ * @file
  * For the collection of memcache stats. This small .js file makes sure that the
  * HTML displaying the stats is inside of the <body> part of the HTML
  * document.
@@ -12,7 +13,7 @@ function memcache_admin_init() {
   }
   else {
     if ($user->uid) {
-      drupal_add_js(drupal_get_path('module', 'memcache_admin'). '/memcache.js');
+      drupal_add_js(drupal_get_path('module', 'memcache_admin') . '/memcache.js');
     }
     register_shutdown_function('memcache_admin_shutdown');
   }
@@ -68,7 +69,7 @@ function memcache_admin_menu() {
         }
       }
 
-      $items['admin/reports/memcache/'. $cluster] = array(
+      $items["admin/reports/memcache/$cluster"] = array(
         'title' => $cluster,
         'type' =>  $count == 0 ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK,
         'page callback' => 'memcache_admin_stats',
@@ -113,6 +114,9 @@ function memcache_admin_admin_settings() {
   return system_settings_form($form);
 }
 
+/**
+ * Helper function. Returns the bin name.
+ */
 function _memcache_admin_default_bin($bin) {
   if ($bin == 'default') {
     return 'cache';
@@ -120,6 +124,9 @@ function _memcache_admin_default_bin($bin) {
   return $bin;
 }
 
+/**
+ * Statistics report: format total and open connections.
+ */
 function _memcache_admin_stats_connections($stats) {
   return t('!current open of !total total', array('!current' => number_format($stats['curr_connections']), '!total' => number_format($stats['total_connections'])));
 }
@@ -354,6 +361,9 @@ function memcache_admin_stats($bin = 'default') {
   return $output;
 }
 
+/**
+ * Callback for the server statistics page.
+ */
 function memcache_admin_stats_raw($bin, $server, $type = 'default') {
   $cluster = memcache_admin_bin_mapping($bin);
   $slab = (int)arg(7);
@@ -366,7 +376,7 @@ function memcache_admin_stats_raw($bin, $server, $type = 'default') {
   $breadcrumbs = array(l(t('Home'), NULL), l(t('Administer'), 'admin'), l(t('Reports'), 'admin/reports'), l(t('Memcache'), 'admin/reports/memcache'), l(t($bin), "admin/reports/memcache/$bin"));
   if ($type == 'slabs' && arg(6) == 'cachedump' && user_access('access slab cachedump')) {
     $breadcrumbs[] = l($server, "admin/reports/memcache/$bin/$server");
-    $breadcrumbs[] = l('slabs', "admin/reports/memcache/$bin/$server/$type");
+    $breadcrumbs[] = l(t('slabs'), "admin/reports/memcache/$bin/$server/$type");
   }
   drupal_set_breadcrumb($breadcrumbs);
   if (isset($stats[$cluster][$server]) && is_array($stats[$cluster][$server]) && count($stats[$cluster][$server])) {
@@ -422,6 +432,9 @@ function theme_memcache_admin_stats_table($variables) {
   return $output;
 }
 
+/**
+ * Returns an array of available statistics types.
+ */
 function memcache_admin_stats_types($bin) {
   module_load_include('inc', 'memcache', 'dmemcache');
   if ($mc = dmemcache_object($bin)) {
@@ -442,6 +455,9 @@ function memcache_admin_stats_types($bin) {
   }
 }
 
+/**
+ * Theme function to produce a table of statistics.
+ */
 function theme_memcache_admin_stats_raw_table($variables) {
   $cluster = $variables['cluster'];
   $server = $variables['server'];
@@ -454,10 +470,10 @@ function theme_memcache_admin_stats_raw_table($variables) {
   if (count(memcache_admin_stats_types($bin)) > 1) {
     foreach (memcache_admin_stats_types($bin) as $type) {
       if ($current_type == $type) {
-        $links[] = '<strong>' . l(t($type), "admin/reports/memcache/$bin/$server/". ($type == 'default' ? '' : $type)) .'</strong>';
+        $links[] = '<strong>' . l(t($type), "admin/reports/memcache/$bin/$server/" . ($type == 'default' ? '' : $type)) . '</strong>';
       }
       else {
-        $links[] = l(t($type), "admin/reports/memcache/$bin/$server/". ($type == 'default' ? '' : $type));
+        $links[] = l(t($type), "admin/reports/memcache/$bin/$server/" . ($type == 'default' ? '' : $type));
       }
     }
   }
@@ -483,7 +499,7 @@ function theme_memcache_admin_stats_raw_table($variables) {
           $k = t('Size');
           $v = format_size($v);
         }
-        else if ($current_type == 'slabs' && user_access('access slab cachedump') && arg(6) == 'cachedump' && $k == 1) {
+        elseif ($current_type == 'slabs' && user_access('access slab cachedump') && arg(6) == 'cachedump' && $k == 1) {
           $k = t('Expire');
           $full_stats = dmemcache_stats($cluster, 'default');
           $infinite = $full_stats[$cluster][$server]['time'] - $full_stats[$cluster][$server]['uptime'];
@@ -495,7 +511,7 @@ function theme_memcache_admin_stats_raw_table($variables) {
           }
         }
         $rs[] = array(check_plain($k), check_plain($v));
-       }
+      }
       $rows[] = array($key, theme('table', array('rows' => $rs)));
     }
     else {
@@ -528,11 +544,14 @@ function _memcache_admin_get_bin_for_cluster($cluster) {
   return $cluster_map[$cluster];
 }
 
+/**
+ * Helper function. Calculate a percentage.
+ */
 function _memcache_admin_stats_percent($a, $b) {
   if ($a == 0) {
     return 0;
   }
-  else if ($b == 0) {
+  elseif ($b == 0) {
     return 100;
   }
   else {
@@ -597,7 +616,8 @@ function memcache_admin_shutdown() {
     }
     if (!empty($output)) {
       // this makes sure all of the HTML is within the <body> even though this <script> is outside it
-      print '<div id="memcache-devel"><h2>'. t('Memcache statistics'). '</h2>'. $output. '</div>';
+      print '<div id="memcache-devel"><h2>' . t('Memcache statistics') . '</h2>' . $output . '</div>';
     }
   }
 }
+
diff --git a/tests/memcache-lock.test b/tests/memcache-lock.test
index 71caf76..32864d2 100644
--- a/tests/memcache-lock.test
+++ b/tests/memcache-lock.test
@@ -1,6 +1,7 @@
 <?php
 
 /**
+ * @file
  * Tests for the lock system.
  */
 class MemcacheLockFunctionalTest extends MemcacheTestCase {
diff --git a/tests/memcache.test b/tests/memcache.test
index 007da61..9ca9056 100644
--- a/tests/memcache.test
+++ b/tests/memcache.test
@@ -1,5 +1,10 @@
 <?php
 
+/**
+ * @file
+ * Test cases for the memcache cache backend.
+ */
+
 class MemcacheTestCase extends DrupalWebTestCase {
   protected $profile = 'testing';
   protected $default_bin = 'cache_memcache';
@@ -236,6 +241,7 @@ class MemcacheTestCase extends DrupalWebTestCase {
 }
 
 class MemCacheSavingCase extends MemcacheTestCase {
+
   public static function getInfo() {
     return array(
       'name' => 'Memcache saving test',
@@ -688,7 +694,7 @@ class MemCacheRealWorldCase extends MemcacheTestCase {
     $this->assertText($original_title, 'Menu item displayed in frontend');
 
     // Change menu item multiple times and check if the change is reflected.
-    for($i=0; $i < 3; $i++) {
+    for ($i=0; $i < 3; $i++) {
       // Edit menu link.
       $edit = array();
       $edit['link_title'] = $this->randomName(16);;
diff --git a/unstable/memcache-session.inc b/unstable/memcache-session.inc
index e31712a..8842c7b 100644
--- a/unstable/memcache-session.inc
+++ b/unstable/memcache-session.inc
@@ -21,20 +21,63 @@ function filter_user_update(&$edit, &$account, $category = NULL) {
   cache_clear_all($account->uid, 'users');
 }
 
+/**
+ * Session handler assigned by session_set_save_handler().
+ *
+ * This function is used to handle any initialization, such as file paths or
+ * database connections, that is needed before accessing session data. Drupal
+ * does not need to initialize anything in this function.
+ *
+ * This function should not be called directly.
+ *
+ * @return bool
+ *   This function will always return TRUE.
+ */
 function _drupal_session_open() {
   return TRUE;
 }
 
+/**
+ * Session handler assigned by session_set_save_handler().
+ *
+ * This function is used to close the current session. Because Drupal stores
+ * session data in the database immediately on write, this function does
+ * not need to do anything.
+ *
+ * This function should not be called directly.
+ *
+ * @return bool
+ *   This function will always return TRUE.
+ */
 function _drupal_session_close() {
   return TRUE;
 }
 
+/**
+ * Reads an entire session from the database (internal use only).
+ *
+ * Also initializes the $user object for the user associated with the session.
+ * This function is registered with session_set_save_handler() to support
+ * database-backed sessions. It is called on every page load when PHP sets
+ * up the $_SESSION superglobal.
+ *
+ * This function is an internal function and must not be called directly.
+ * Doing so may result in logging out the current user, corrupting session data
+ * or other unexpected behavior. Session data must always be accessed via the
+ * $_SESSION superglobal.
+ *
+ * @param string $key
+ *   The session ID of the session to retrieve.
+ *
+ * @return mixed
+ *   The user's session, or an empty string if no session exists.
+ */
 function _drupal_session_read($key) {
   global $user;
 
-  // Write and Close handlers are called after destructing objects since PHP 5.0.5
-  // Thus destructors can use sessions but session handler can't use objects.
-  // So we are moving session closure before destructing objects.
+  // Write and Close handlers are called after destructing objects since
+  // PHP 5.0.5 Thus destructors can use sessions but session handler can't use
+  // objects. So we are moving session closure before destructing objects.
   register_shutdown_function('session_write_close');
 
   // Handle the case of first time visitors and clients that don't store
@@ -66,19 +109,20 @@ function _drupal_session_read($key) {
  *   1b. With session data.
  *   1c. Session saving has been turned off programatically
  *       (see drupal_save_session()).
- *   1d. Without session data but had session data at the beginning of the request
- *       (thus a write must be made to clear stored session data).
+ *   1d. Without session data but had session data at the beginning of the
+ *       request (thus a write must be made to clear stored session data).
  * 2. Authenticated user.
  *   2a. Without session data.
  *   2b. With session data.
  *   2c. Session saving has been turned off programatically
  *       (see drupal_save_session()).
  *
- * @param $key
+ * @param string $key
  *   The session ID.
- * @param $value
+ * @param mixed $value
  *   Any data to store in the session.
- * @return
+ *
+ * @return bool
  *   TRUE.
  */
 function _drupal_session_write($key, $value) {
@@ -89,7 +133,7 @@ function _drupal_session_write($key, $value) {
   }
 
   // Prepare the information to be saved.
-  $session = new stdClass;
+  $session = new stdClass();
   $session->sid = $key;
   $session->uid = $user->uid;
   $session->cache = isset($user->cache) ? $user->cache : '';
@@ -135,8 +179,8 @@ function _drupal_session_write($key, $value) {
 /**
  * Called by PHP session handling with the PHP session ID to end a user's session.
  *
- * @param  string $sid
- *   the session id
+ * @param string $sid
+ *   The session id.
  */
 function _drupal_session_destroy($sid) {
   dmemcache_delete($sid, 'session');
@@ -149,6 +193,14 @@ function _drupal_session_destroy($sid) {
   _drupal_session_delete_cookie(session_name());
 }
 
+/**
+ * Session handler assigned by session_set_save_handler().
+ *
+ * Does nothing with memcache.
+ *
+ * @param int $lifetime
+ *   The value of session.gc_maxlifetime, passed by PHP.
+ */
 function _drupal_session_garbage_collection($lifetime) {
   // Automatic with memcached.
   // Be sure to adjust 'php_value session.gc_maxlifetime' to a large enough
@@ -190,11 +242,19 @@ function drupal_session_initialize() {
 
 
 /**
- * Counts how many users have sessions. Can count either anonymous sessions, authenticated sessions, or both.
- * Would be insane slow with memcached as we would need to retrieve at least the stats of all object.
+ * Counts how many users have sessions.
+ *
+ * Can count either anonymous sessions, authenticated sessions, or both.
+ * Would be insane slow with memcached as we would need to retrieve at least
+ * the stats of all object.
  * Not implemented.
+ *
+ * @param int $timestamp
+ *   Ignored.
+ * @param bool $anonymous
+ *   Ignored.
  */
-function drupal_session_count($timestamp = 0, $anonymous = true) {
+function drupal_session_count($timestamp = 0, $anonymous = TRUE) {
 }
 
 /**
@@ -306,13 +366,16 @@ function drupal_session_destroy_uid($uid) {
 /**
  * Determine whether to save session data of the current request.
  *
- * This function allows the caller to temporarily disable writing of session data,
- * should the request end while performing potentially dangerous operations, such as
- * manipulating the global $user object.  See http://drupal.org/node/218104 for usage
+ * This function allows the caller to temporarily disable writing of session
+ * data, should the request end while performing potentially dangerous
+ * operations, such as manipulating the global $user object.
+ * See http://drupal.org/node/218104 for usage
  *
- * @param $status
- *   Disables writing of session data when FALSE, (re-)enables writing when TRUE.
- * @return
+ * @param bool $status
+ *   Disables writing of session data when FALSE, (re-)enables writing
+ *   when TRUE.
+ *
+ * @return bool
  *   FALSE if writing session data has been disabled. Otherwise, TRUE.
  */
 function drupal_save_session($status = NULL) {
@@ -326,10 +389,11 @@ function drupal_save_session($status = NULL) {
 /**
  * Create the user object.
  *
- * @param $session
+ * @param object $session
  *   The session object (see sess_write() for the structure).
- * @return $user
- *   The user object.
+ *
+ * @return object
+ *   The $user object.
  */
 function _memcache_session_user_load($session) {
   // We found the client's session record and they are an authenticated user.
@@ -357,7 +421,7 @@ function _memcache_session_user_load($session) {
         $user->session = empty($session->session) ? '' : $session->session;
         $user->data = unserialize($user->data);
 
-        // Add roles element to $user
+        // Add roles element to $user.
         $user->roles = array();
         $user->roles[DRUPAL_AUTHENTICATED_RID] = 'authenticated user';
         $result = db_query("SELECT r.rid, r.name FROM {role} r INNER JOIN {users_roles} ur ON ur.rid = r.rid WHERE ur.uid = :uid", array(':uid' => $user->uid));
@@ -366,7 +430,7 @@ function _memcache_session_user_load($session) {
         }
       }
     }
-    else if ($user->uid) {
+    elseif ($user->uid) {
       // Got a user object from 'users' memcache bin. Mark it in case modules
       // want to know that this user was created from memcache.
       $user->from_cache = TRUE;
@@ -377,8 +441,9 @@ function _memcache_session_user_load($session) {
       // was successfully retrieved from the 'users' bin, and that user
       // object's uid is 0. Not sure why this would ever happen. Leaving former
       // comment in:
-      // This is a rare case that we have a session cached, but no session user object cached.
-      // This usually only happens if you kill memcached and restart it.
+      // This is a rare case that we have a session cached, but no session user
+      // object cached. This usually only happens if you kill memcached and
+      // restart it.
       $user = drupal_anonymous_user();
       $user->session = empty($session->session) ? '' : $session->session;
     }
@@ -396,10 +461,10 @@ function _memcache_session_user_load($session) {
 /**
  * Deletes the session cookie.
  *
- * @param $name
+ * @param stromg $name
  *   Name of session cookie to delete.
- * @param $force_insecure
- *   Fornce cookie to be insecure.
+ * @param bool $force_insecure
+ *   Force cookie to be insecure.
  */
 function _drupal_session_delete_cookie($name, $force_insecure = FALSE) {
   if (isset($_COOKIE[$name])) {
@@ -408,4 +473,3 @@ function _drupal_session_delete_cookie($name, $force_insecure = FALSE) {
     unset($_COOKIE[$name]);
   }
 }
-
