diff --git a/lib/Drupal/masquerade/Tests/MasqueradeTest.php b/lib/Drupal/masquerade/Tests/MasqueradeTest.php
index d1bdd1e..d25d9e7 100644
--- a/lib/Drupal/masquerade/Tests/MasqueradeTest.php
+++ b/lib/Drupal/masquerade/Tests/MasqueradeTest.php
@@ -42,7 +42,10 @@ class MasqueradeTest extends WebTestBase {
     $this->assertResponse(403);
 
     // Verify that the admin user is able to masquerade.
+    $this->assertSessionByUid($this->admin_user->uid, FALSE);
     $this->masqueradeAs($this->web_user);
+    $this->assertSessionByUid($this->web_user->uid, $this->admin_user->uid);
+    $this->assertNoSessionByUid($this->admin_user->uid);
 
     // Verify that a token is required to unmasquerade.
     $this->drupalGet('unmasquerade');
@@ -58,6 +61,8 @@ class MasqueradeTest extends WebTestBase {
 
     // Verify that the user can unmasquerade.
     $this->unmasquerade($this->web_user);
+    $this->assertNoSessionByUid($this->web_user->uid);
+    $this->assertSessionByUid($this->admin_user->uid, FALSE);
   }
 
   /**
@@ -107,6 +112,87 @@ class MasqueradeTest extends WebTestBase {
   }
 
   /**
+   * Asserts that there is a session for a given user ID.
+   *
+   * @param int $uid
+   *   The user ID for which to find a session record.
+   * @param int|false $expected_masquerading_uid
+   *   (optional) The expected value of the 'masquerading' session data. Pass
+   *   FALSE to assert that the session data is not set.
+   *
+   * @return stdClass
+   *   The session record from {sessions}, if any.
+   */
+  protected function assertSessionByUid($uid, $expected_masquerading_uid = NULL) {
+    $result = db_query('SELECT * FROM {sessions} WHERE uid = :uid', array(
+      ':uid' => $uid,
+    ))->fetchAll();
+    // If there is more than one session, then that must be unexpected.
+    if (count($result) > 1) {
+      $this->fail("Found more than 1 session for uid $uid.");
+    }
+    else {
+      $this->pass("Found session for uid $uid.");
+      $session = reset($result);
+
+      // Decode the session data.
+      if (!empty($session->session)) {
+        // Careful: PHP does not provide a utility function that decodes session
+        // data only. session_decode() merges the input into the global
+        // $_SESSION (but only if it is an array).
+        // @see http://php.net/manual/function.session-decode.php
+        $old_session = isset($_SESSION) ? $_SESSION : NULL;
+        // Furthermore, if this test is executed on the command line, then
+        // Drupal denies to start a session. PHP throws a notice if the session
+        // is attempted to be started more than once.
+        // @see drupal_session_start()
+        @session_start();
+        // In any case, ensure that it is empty.
+        $_SESSION = array();
+
+        if (!session_decode($session->session)) {
+          $this->fail(format_string('Failed to decode session data: @data', array('@data' => $session->session)));
+        }
+        $session->session = isset($_SESSION) ? $_SESSION : array();
+
+        // Restore the original global session.
+        $_SESSION = NULL;
+        if (isset($old_session)) {
+          $_SESSION = $old_session;
+        }
+      }
+      else {
+        $session->session = array();
+      }
+
+      if (isset($expected_masquerading_uid)) {
+        if ($expected_masquerading_uid !== FALSE) {
+          $this->assertEqual($session->session['masquerading'], $expected_masquerading_uid, format_string('$_SESSION[\'masquerading\'] equals @uid.', array(
+            '@uid' => $expected_masquerading_uid,
+          )));
+        }
+        else {
+          $this->assert(!isset($session->session['masquerading']), '$_SESSION[\'masquerading\'] is not set.');
+        }
+      }
+      return $session;
+    }
+  }
+
+  /**
+   * Asserts that no session exists for a given uid.
+   *
+   * @param int $uid
+   *   The user ID to assert.
+   */
+  protected function assertNoSessionByUid($uid) {
+    $result = db_query('SELECT * FROM {sessions} WHERE uid = :uid', array(
+      ':uid' => $uid,
+    ))->fetchAll();
+    $this->assert(empty($result), "No session for uid $uid found.");
+  }
+
+  /**
    * Stop-gap fix.
    *
    * @see http://drupal.org/node/1555862
diff --git a/masquerade.install b/masquerade.install
index d062da1..06461f3 100644
--- a/masquerade.install
+++ b/masquerade.install
@@ -6,42 +6,10 @@
  */
 
 /**
- * Implements hook_schema().
+ * Remove the {masquerade} table.
  */
-function masquerade_schema() {
-  $schema['masquerade'] = array(
-      'description' => 'Each masquerading user has their session recorded into the masquerade table. Each record represents a masquerading user.',
-      'fields' => array(
-        'sid' => array(
-          'description' => 'The current session for this masquerading user corresponding to their {sessions}.sid.',
-          'type' => 'varchar',
-          'length' => '64',
-          'not null' => TRUE,
-          'default' => ''),
-        'uid_from' => array(
-          'description' => 'The {users}.uid corresponding to a session.',
-          'type' => 'int',
-          'not null' => TRUE,
-          'default' => 0,
-          'disp-width' => '10'),
-        'uid_as' => array(
-          'description' => 'The {users}.uid this session is masquerading as.',
-          'type' => 'int',
-          'not null' => TRUE,
-          'default' => 0,
-          'disp-width' => '10'),
-      ),
-      'indexes' => array(
-        'sid' => array('sid', 'uid_from'),
-        'sid_2' => array('sid', 'uid_as'),
-      ),
-  );
-  return $schema;
-}
-
-/**
- * Implements hook_install().
- */
-function masquerade_install() {
-  module_set_weight('masquerade', -10);
+function masquerade_update_8200() {
+  if (db_table_exists('masquerade')) {
+    db_drop_table('masquerade');
+  }
 }
diff --git a/masquerade.module b/masquerade.module
index 28cb064..f401a49 100644
--- a/masquerade.module
+++ b/masquerade.module
@@ -34,44 +34,6 @@ function masquerade_permission() {
 }
 
 /**
- * Implements hook_init().
- */
-function masquerade_init() {
-  global $user;
-
-  if (isset($_SESSION['masquerading'])) {
-    return;
-  }
-  // Try to load masqing uid from masquerade table.
-  $uid = db_query("SELECT uid_from FROM {masquerade} WHERE sid = :sid AND uid_as = :uid_as", array(
-    ':sid' => session_id(),
-    ':uid_as' => $user->uid,
-  ))->fetchField();
-  if ($uid) {
-    $_SESSION['masquerading'] = $uid;
-  }
-  elseif (isset($_SESSION['masquerading'])) {
-    unset($_SESSION['masquerading']);
-  }
-}
-
-/**
- * Implements hook_cron().
- *
- * Cleanup masquerade records where people didn't use the switch back link
- * that would have cleanly removed the user switch record.
- */
-function masquerade_cron() {
-  // see http://drupal.org/node/268487 before modifying this query
-  $subquery = db_select('sessions', 's');
-  $subquery->addField('s', 'sid');
-
-  $query = db_delete('masquerade');
-  $query->condition('sid', $subquery, 'NOT IN');
-  $query->execute();
-}
-
-/**
  * Implements hook_menu().
  */
 function masquerade_menu() {
@@ -178,22 +140,6 @@ function masquerade_user_is_masquerading() {
 }
 
 /**
- * Implements hook_user_logout().
- */
-function masquerade_user_logout($account) {
-  if (!empty($account->masquerading)) {
-    global $user;
-    $real_user = user_load($user->masquerading);
-    watchdog('masquerade', "User %user no longer masquerading as %masq_as.", array('%user' => $real_user->name, '%masq_as' => $user->name), WATCHDOG_INFO);
-
-    $query = db_delete('masquerade');
-    $query->condition('sid', session_id());
-    $query->condition('uid_as', $account->uid);
-    $query->execute();
-  }
-}
-
-/**
  * Implements hook_user_view().
  */
 function masquerade_user_view(User $account, $display, $view_mode, $langcode) {
@@ -348,14 +294,6 @@ function masquerade_switch_user(User $target_account) {
 
   $_SESSION['masquerading'] = $user->uid;
 
-  $query = db_insert('masquerade');
-  $query->fields(array(
-    'uid_from' => $user->uid,
-    'uid_as' => $target_account->uid,
-    'sid' => session_id(),
-  ));
-  $query->execute();
-
   watchdog('masquerade', 'User %username masqueraded as %target_username.', array(
     '%username' => $user->name,
     '%target_username' => $target_account->name,
@@ -398,15 +336,11 @@ function masquerade_switch_back_page() {
  */
 function masquerade_switch_back() {
   global $user;
-  $uid = db_query('SELECT uid_from FROM {masquerade} WHERE sid = :sid AND uid_as = :uid_as', array(
-    ':sid' => session_id(),
-    ':uid_as' => $user->uid,
-  ))->fetchField();
-
-  // Clean-up session masquerate.
-  db_delete('masquerade')
-    ->condition('sid', session_id())
-    ->execute();
+
+  if (!masquerade_user_is_masquerading()) {
+    return FALSE;
+  }
+  $uid = $_SESSION['masquerading'];
 
   $old_user = $user;
 
