diff --git og_user_roles.module og_user_roles.module
index bd7ccef..4ab6269 100644
--- og_user_roles.module
+++ og_user_roles.module
@@ -2346,13 +2346,14 @@ function og_user_roles_get_groups_result() {
  * This function takes the global $user (or $account) value and returns a list
  * of group and non-group roles for this user.
  */
-function og_user_roles_all_roles($user) {
+function og_user_roles_all_roles($account) {
 
+  global $user;
   drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); // added as per this issue: http://drupal.org/node/149469
 //  drupal_bootstrap(DRUPAL_BOOTSTRAP_PATH); // added as per this issue: http://drupal.org/node/149469
 
   // This will be the process to get BOTH the group and non-group roles for a user
-  $uid = $user->uid;
+  $uid = $account->uid;
   $gid = 0;
   $gids = array();
   $nid = 0;
@@ -2382,9 +2383,14 @@ function og_user_roles_all_roles($user) {
   $gid = $gid02;
   if ($gid02 === NULL) {
     $gid = 0;
-  }else{
-    if (isset($_SESSION['og_last'])) $_SESSION['og_last'] = $group_node->nid;
-    $_SESSION['og_user_role'] = $gid;
+  }
+  else {
+    if (isset($_SESSION['og_last'])) {
+      $_SESSION['og_last'] = $gid;
+    }
+    if ($user->uid != 0) {
+      $_SESSION['og_user_role'] = $gid;
+    }
   }
 
   //
@@ -2879,9 +2885,14 @@ function og_user_roles_all_roles($user) {
   //
   if (empty($gid)) {
     $gid = 0; // This prevents us from getting error on non-group node/add
-  }else{
-    if (isset($_SESSION['og_last'])) $_SESSION['og_last'] = $gid;
-    $_SESSION['og_user_role'] = $gid;
+  }
+  else {
+    if (isset($_SESSION['og_last'])) {
+      $_SESSION['og_last'] = $gid;
+    }
+    if ($user->uid != 0) {
+      $_SESSION['og_user_role'] = $gid;
+    }
   }
 
 /*
@@ -2903,12 +2914,12 @@ function og_user_roles_all_roles($user) {
   }
 
   //
-  // First, we need to create an array of $user->roles
+  // First, we need to create an array of $account->roles
   //
-  $c = $user->roles;
+  $c = $account->roles;
 
   //
-  // Next, we add the $user->roles array to the $ogroles array, if there is an ogroles array;
+  // Next, we add the $account->roles array to the $ogroles array, if there is an ogroles array;
   //
   if ($x1 > 0) {
     $d = array();
@@ -2926,10 +2937,10 @@ function og_user_roles_all_roles($user) {
 	} else {
 	  $d1 = '';
 	}
-    og_user_roles_write_test($user, $location, $gid02, $gid, $uri_request_id, $d1, $ref);
+    og_user_roles_write_test($account, $location, $gid02, $gid, $uri_request_id, $d1, $ref);
   }
 
-  // $d is either the merged results, or just $user->roles;
+  // $d is either the merged results, or just $account->roles;
 
   return $d;
 } // end og_user_roles_all_roles()
@@ -3051,14 +3062,14 @@ function og_user_roles_table_exists($table) {
 /**
  * See what is found in user_all_roles.
  */
-function og_user_roles_write_test($user, $location, $gid02, $gid, $uri_request_id, $d, $ref, $test_function = 'og_user_roles_all_roles') {
+function og_user_roles_write_test($account, $location, $gid02, $gid, $uri_request_id, $d, $ref, $test_function = 'og_user_roles_all_roles') {
   drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);  // http://drupal.org/node/273068
   $test_status = '';
   $test_date = format_date(time(), 'custom', 'Y-m-d h:i:s a');
   $test_user = $user->uid;
   $test_subfunction = $location;
   $test_string = 'group context: '. $gid02;
-  $test_username = $user->name;
+  $test_username = $account->name;
   $test_group = $gid;
   $test_uri = $uri_request_id . " (" . $ref . ")";
   $test_aarg0 = arg(0);
