--- masquerade.orig	Sat Jul  8 11:25:51 2006
+++ masquerade.module	Sat Jul  8 11:25:32 2006
@@ -25,17 +25,18 @@
 function masquerade_menu($may_cache) {
   $items = array();
   if ($may_cache) {
+    global $user;
+
     $items[] = array('path' => 'masquerade/switch', 
       'title' => t('switch user'),
       'callback' => 'masquerade_switch_user',
-      'access' => !$user->masquerading && (user_access('masquerade as user') || user_access('masquerade as admin')),
+      'access' => !$GLOBALS['masquerading'] && (user_access('masquerade as user') || user_access('masquerade as admin')),
       'type' => MENU_CALLBACK);
 
-    global $user;
     $items[] = array('path' => 'masquerade/unswitch', 
       'title' => t('switch back'),
       'callback' => 'masquerade_switch_back',
-      'access' => $user->masquerading,
+      'access' => $GLOBALS['masquerading'],
       'type' => MENU_NORMAL_ITEM);
   }
 
@@ -52,8 +53,11 @@
   $uid = db_result(db_query("SELECT uid_from FROM {masquerade} WHERE sid = '%s' AND uid_as = %d", session_id(), $user->uid));
   // using if so that we get unset rather than false if not masqing
   if ($uid) {
-    $user->masquerading = $uid;
+    $GLOBALS['masquerading'] = $uid;
   }
+	else{
+    $GLOBALS['masquerading'] = null;
+	}
 }
 
 /**
