diff --git a/dmemcache.inc b/dmemcache.inc
index be252ef..2d470ff 100644
--- a/dmemcache.inc
+++ b/dmemcache.inc
@@ -1,36 +1,42 @@
 <?php
 
-/*
+/**
+ * @file
  * Core dmemcache functions required by:
  *   memcache.inc
  *   memcache.db.inc
- *   session-memcache.inc
- *   session-memcache.db.inc
+ *   memcache-session.inc
  */
 
 global $_memcache_statistics;
 $_memcache_statistics = array();
 
-/*
+/**
  * A memcache API for Drupal.
  */
 
 /**
- *  Place an item into memcache
+ * Place 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.
  *
  * @return bool
+ *   FALSE if placing the item into memcache failed.
  */
 function dmemcache_set($key, $value, $exp = 0, $bin = 'cache', $mc = NULL) {
   global $_memcache_statistics;
@@ -48,25 +54,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) {
   global $_memcache_statistics;
@@ -86,10 +99,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) {
   global $_memcache_statistics;
@@ -118,10 +134,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) {
   global $_memcache_statistics;
@@ -151,7 +170,7 @@ function dmemcache_get_multi($keys, $bin = 'cache', $mc = NULL) {
     }
   }
   foreach ($statistics as $key => $values) {
-    $values[] = isset($results[$key]) ? '1': '0';
+    $values[] = isset($results[$key]) ? '1' : '0';
     $_memcache_statistics[] = $values;
   }
 
@@ -172,10 +191,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) {
   global $_memcache_statistics;
@@ -188,14 +210,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.
  *
- * @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.
+ * 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.
  *
- * @return Returns TRUE on success or FALSE on failure.
+ * @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 bool
+ *   Returns TRUE on success or FALSE on failure.
  */
 function dmemcache_flush($bin = 'cache', $mc = NULL) {
   global $_memcache_statistics;
@@ -205,11 +231,21 @@ function dmemcache_flush($bin = 'cache', $mc = NULL) {
   }
 }
 
+/**
+ * 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) {
@@ -221,13 +257,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 {
@@ -240,8 +276,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)) {
@@ -264,20 +307,23 @@ function dmemcache_stats($stats_bin = 'cache', $stats_type = 'default', $aggrega
 }
 
 /**
- * Returns an Memcache object based on the bin requested. Note that there is
- * nothing preventing developers from calling this function directly to get the
- * Memcache object. Do this if you need functionality not provided by this API
- * or if you need to use legacy code. Otherwise, use the dmemcache (get, set,
- * delete, flush) API functions provided here.
+ * Returns a Memcache object based on the bin requested.
  *
- * @param $bin The bin which is to be used.
+ * Note that there is nothing preventing developers from calling this function
+ * directly to get the Memcache object. Do this if you need functionality not
+ * provided by this API or if you need to use legacy code. Otherwise, use the
+ * dmemcache (get, set, delete, flush) API functions provided here.
  *
- * @param $flush Rebuild the bin/server/cache mapping.
+ * @param string $bin
+ *   The bin which is to be used.
+ * @param bool $flush
+ *   Rebuild the bin/server/cache mapping.
  *
- * @return an Memcache object or FALSE.
+ * @return mixed
+ *   A Memcache object or FALSE.
  */
 function dmemcache_object($bin = NULL, $flush = FALSE) {
-  static $extension, $memcacheCache = array(), $memcache_servers, $memcache_bins, $memcache_persistent, $failed_connection_cache;
+  static $extension, $memcache_cache = array(), $memcache_servers, $memcache_bins, $memcache_persistent, $failed_connection_cache;
 
   if (!isset($extension)) {
     // If an extension is specified in settings.php, use that when available.
@@ -299,20 +345,20 @@ function dmemcache_object($bin = NULL, $flush = FALSE) {
     // Indicate whether to connect to memcache using a persistent connection.
     // Note: this only affects the Memcache PECL extension, and does not
     // affect the Memcached PECL extension.  For a detailed explanation see:
-    //  http://drupal.org/node/822316#comment-4427676
+    // http://drupal.org/node/822316#comment-4427676
     if (!isset($memcache_persistent)) {
       $memcache_persistent = variable_get('memcache_persistent', FALSE);
     }
   }
 
   if ($flush) {
-    foreach ($memcacheCache as $cluster) {
+    foreach ($memcache_cache as $cluster) {
       memcache_close($cluster);
     }
-    $memcacheCache = array();
+    $memcache_cache = array();
   }
 
-  if (empty($memcacheCache) || empty($memcacheCache[$bin])) {
+  if (empty($memcache_cache) || empty($memcache_cache[$bin])) {
     // $memcache_servers and $memcache_bins originate from settings.php.
     // $memcache_servers_custom and $memcache_bins_custom get set by
     // memcache.module. They are then merged into $memcache_servers and
@@ -323,19 +369,21 @@ function dmemcache_object($bin = NULL, $flush = FALSE) {
       $memcache_bins    = variable_get('memcache_bins', array('cache' => 'default'));
     }
 
-    // If there is no cluster for this bin in $memcache_bins, cluster is 'default'.
+    // If there is no cluster for this bin in $memcache_bins, cluster is
+    // 'default'.
     $cluster = empty($memcache_bins[$bin]) ? 'default' : $memcache_bins[$bin];
 
     // If this bin isn't in our $memcache_bins configuration array, and the
     // 'default' cluster is already initialized, map the bin to 'cache' because
     // we always map the 'cache' bin 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. Each cluster gets its own Memcache object.
+      // Create a new Memcache object. Each cluster gets its own Memcache
+      // object.
       if ($extension == 'Memcached') {
-        $memcache = new Memcached;
+        $memcache = new Memcached();
         $default_opts = array(
           Memcached::OPT_COMPRESSION => FALSE,
           Memcached::OPT_DISTRIBUTION => Memcached::DISTRIBUTION_CONSISTENT,
@@ -351,7 +399,7 @@ function dmemcache_object($bin = NULL, $flush = FALSE) {
         }
       }
       elseif ($extension == 'Memcache') {
-        $memcache = new Memcache;
+        $memcache = new Memcache();
       }
       else {
         drupal_set_message(t('You must enable the PECL memcached or memcache extension to use memcache.inc.'), 'error');
@@ -369,7 +417,8 @@ function dmemcache_object($bin = NULL, $flush = FALSE) {
           if ($memcache instanceof Memcache) {
             // Support unix sockets in the format 'unix:///path/to/socket'.
             if ($host == 'unix') {
-              // When using unix sockets with Memcache use the full path for $host.
+              // When using unix sockets with Memcache use the full path for
+              // $host.
               $host = $s;
               // Port is always 0 for unix sockets.
               $port = 0;
@@ -400,7 +449,8 @@ function dmemcache_object($bin = NULL, $flush = FALSE) {
           else {
             // Support unix sockets in the format 'unix:///path/to/socket'.
             if ($host == 'unix') {
-              // Memcached expects just the path to the socket without the protocol
+              // Memcached expects just the path to the socket without the
+              // protocol.
               $host = substr($s, 7);
               // Port is always 0 for unix sockets.
               $port = 0;
@@ -422,23 +472,34 @@ function dmemcache_object($bin = NULL, $flush = FALSE) {
 
       if ($init) {
         // 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 b4e3550..32b2e8c 100644
--- a/memcache.inc
+++ b/memcache.inc
@@ -1,5 +1,10 @@
 <?php
 
+/**
+ * @file
+ * Implementation of cache.inc with memcache logic included.
+ */
+
 require_once dirname(__FILE__) . '/dmemcache.inc';
 
 /**
@@ -9,22 +14,29 @@ define('MEMCACHE_WILDCARD_INVALIDATE', 86400 * 28);
 
 define('MEMCACHE_CONTENT_CLEAR', 'MEMCACHE_CONTENT_CLEAR');
 
-/** Implementation of cache.inc with memcache logic included **/
-
 class MemCacheDrupal implements DrupalCacheInterface {
-  function __construct($bin) {
+  /**
+   * Constructs a new MemCacheDrupal object.
+   */
+  public function __construct($bin) {
     $this->memcache = dmemcache_object($bin);
     $this->bin = $bin;
 
     $this->reloadVariables();
   }
 
-  function get($cid) {
+  /**
+   * Implements DrupalCacheInterface::get().
+   */
+  public function get($cid) {
     $cache = dmemcache_get($cid, $this->bin, $this->memcache);
     return $this->valid($cid, $cache) ? $cache : FALSE;
   }
 
-  function getMultiple(&$cids) {
+  /**
+   * Implements DrupalCacheInterface::getMultiple().
+   */
+  public function getMultiple(&$cids) {
     $results = dmemcache_get_multi($cids, $this->bin, $this->memcache);
     foreach ($results as $cid => $result) {
       if (!$this->valid($cid, $result)) {
@@ -38,15 +50,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)) {
@@ -78,7 +101,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;
         }
       }
@@ -100,9 +123,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);
         }
@@ -112,11 +135,14 @@ class MemCacheDrupal implements DrupalCacheInterface {
     return (bool) $cache;
   }
 
-  function set($cid, $data, $expire = CACHE_PERMANENT, array $headers = NULL) {
+  /**
+   * Implements DrupalCacheInterface::set().
+   */
+  public function set($cid, $data, $expire = CACHE_PERMANENT, array $headers = NULL) {
     $created = time();
 
     // Create new cache object.
-    $cache = new stdClass;
+    $cache = new stdClass();
     $cache->cid = $cid;
     $cache->data = is_object($data) ? clone $data : $data;
     $cache->created = $created;
@@ -129,7 +155,7 @@ class MemCacheDrupal implements DrupalCacheInterface {
       $cache->expire = REQUEST_TIME + 2591999;
     }
     // 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;
@@ -153,7 +179,10 @@ class MemCacheDrupal implements DrupalCacheInterface {
     dmemcache_set($cid, $cache, $memcache_expire, $this->bin, $this->memcache);
   }
 
-  function clear($cid = NULL, $wildcard = FALSE) {
+  /**
+   * Implements DrupalCacheInterface::clear().
+   */
+  public function clear($cid = NULL, $wildcard = FALSE) {
     if ($this->memcache === FALSE) {
       // No memcache connection.
       return;
@@ -206,9 +235,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'];
           }
@@ -220,7 +249,7 @@ class MemCacheDrupal implements DrupalCacheInterface {
         }
       }
       else {
-        // Register a wildcard flush for current cid
+        // Register a wildcard flush for current cid.
         $this->wildcards($cid, TRUE);
       }
     }
@@ -233,15 +262,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.
@@ -356,17 +394,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;
   }
@@ -377,7 +418,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);
@@ -389,7 +430,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 347c339..b1059d1 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) {
diff --git a/memcache.module b/memcache.module
index 92f76a3..c72b11a 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.
diff --git a/memcache_admin/memcache_admin.install b/memcache_admin/memcache_admin.install
index 0622b20..ef5ae4d 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/tests/memcache-lock.test b/tests/memcache-lock.test
index 4bfff7b..c3744c0 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 DrupalWebTestCase {
diff --git a/unstable/memcache-session.inc b/unstable/memcache-session.inc
index 0b433bb..0011e49 100644
--- a/unstable/memcache-session.inc
+++ b/unstable/memcache-session.inc
@@ -13,7 +13,7 @@
 require_once dirname(__FILE__) . '/dmemcache.inc';
 
 /**
- * Implement hook_user() using a required module's namespace since memcache is 
+ * Implement hook_user() using a required module's namespace since memcache is
  * not a module and thus can't implement hooks directly.
  */
 function filter_user($op, &$edit, &$account, $category = NULL) {
@@ -23,20 +23,63 @@ function filter_user($op, &$edit, &$account, $category = NULL) {
   }
 }
 
+/**
+ * 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
@@ -68,19 +111,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) {
@@ -91,7 +135,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 : '';
@@ -136,8 +180,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');
@@ -150,6 +194,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
@@ -191,11 +243,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) {
 }
 
 /**
@@ -307,13 +367,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) {
@@ -327,10 +390,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.
@@ -358,7 +422,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));
@@ -367,7 +431,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;
@@ -378,8 +442,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;
     }
@@ -397,10 +462,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])) {
@@ -409,4 +474,3 @@ function _drupal_session_delete_cookie($name, $force_insecure = FALSE) {
     unset($_COOKIE[$name]);
   }
 }
-
