diff --git a/sudo.module b/sudo.module
index d7de32c..b11cb6d 100755
--- a/sudo.module
+++ b/sudo.module
@@ -28,7 +28,11 @@ function sudo_form_system_site_maintenance_settings_alter(&$form, $form_state) {
 
 function sudo_preprocess_page(&$vars) {
   global $user;
-  if ($user->uid && !variable_get('sudo_hide_button', FALSE) && is_array($sudo_roles = sudo_roles())) { // intentional assignment of $sudo_roles
+  if (!$user->uid || variable_get('sudo_hide_button', FALSE)) { 
+    return; 
+  } 
+  $sudo_roles = sudo_roles();
+  if (!empty($sudo_roles)) { 
     $_SESSION['sudoing'] = !(count(array_diff($sudo_roles, array_keys($user->roles))));
     $state = $_SESSION['sudoing'] ? 'sudoing' : 'normal';
     if (variable_get('sudo_button_path', FALSE)) {
