diff --git a/autologout.admin.inc b/autologout.admin.inc
index 18f46a9..20170ed 100644
--- a/autologout.admin.inc
+++ b/autologout.admin.inc
@@ -61,7 +61,7 @@ function autologout_settings() {
     '#default_value' => variable_get('autologout_message', 'Your session is about to expire. Do you want to reset it?'),
     '#size' => 40,
     '#description' => t('This message must be plain text as it might appear in a javascript confirm dialog.')
-  );  
+  );
   $form['autologout_use_watchdog'] = array(
    '#type' => 'checkbox',
    '#title' => t('Enable watchdog Automated Logout logging'),
@@ -73,55 +73,59 @@ function autologout_settings() {
    '#title' => t('Enforce auto logout on admin pages'),
    '#default_value' => variable_get('autologout_enforce_admin', FALSE),
    '#description' => t('If checked, than users will be auto logged out when administering the site.')
-  );  
+  );
   $form['table'] = array(
       '#type' => 'item',
       '#weight' => -2,
       '#title' => t('If Enabled every user in role will be logged out based on that roles timeout, unless the user has an indivual timeout set.'),
-      '#theme' => 'autologout_render_table',      
+      '#theme' => 'autologout_render_table',
   );
 
-	foreach (user_roles(TRUE) as $key => $role){
-    
-		$form['table']['autologout_roles']['autologout_role_'. $key .'_timeout'] = array(
-			'#type' => 'textfield',
-			'#default_value' => variable_get('autologout_role_' . $key.'_timeout', $timeout),
-			'#size' => 8,
-			'#theme' => 'textfield',
-		);
-
-	}
+  foreach (user_roles(TRUE) as $key => $role){
+    $form['table']['autologout_roles']['autologout_role_'. $key .'_timeout'] = array(
+      '#type' => 'textfield',
+      '#default_value' => variable_get('autologout_role_' . $key.'_timeout', $timeout),
+      '#size' => 8,
+      '#theme' => 'textfield',
+    );
+  }
 
-	foreach (user_roles(TRUE) as $key => $role){
-		 $form['table']['autologout_roles']['autologout_role_' . $key] = array(
-			  '#type' => 'checkbox',
-			  '#default_value' => variable_get('autologout_role_' . $key, FALSE),
-			  '#theme' => 'checkbox'
-		  );	   
-	}
-  return system_settings_form($form);  
+  foreach (user_roles(TRUE) as $key => $role){
+    $form['table']['autologout_roles']['autologout_role_' . $key] = array(
+      '#type' => 'checkbox',
+      '#default_value' => variable_get('autologout_role_' . $key, FALSE),
+      '#theme' => 'checkbox'
+    );
+  }
+  return system_settings_form($form);
 }
 
+/**
+ * Validation function for the settings form.
+ */
+function autologout_settings_validate($form, &$form_state) {
+  $max_timeout = $form_state['values']['max_timeout'];
+  $role_based_logout = $form_state['values']['autologout_role_logout'];
 
-function autologout_settings_validate($form, &$form_state) {  
-$max_timeout = $form_state['values']['max_timeout'];
-$role_timeout = _autologout_get_role_timeout();
-
-   // Validate timeouts for each role
-  foreach (user_roles(TRUE) as $key => $role) {
-  $timeout = $form_state['values']['autologout_role_'.$key.'_timeout'];
-  $validate = autologout_timeout_validate($timeout);
-    if(!$validate){
-      form_set_error($key.'timeout', t('%role timeout must be an integer greater than 60, and less then %max.', array('%role' => $role,'%max' => $max_timeout)));
+  // Validate timeouts for each role if the role-based settings are being used.
+  if ($role_based_logout) {
+    foreach (user_roles(TRUE) as $key => $role) {
+      // Only validate this role if it has autologout enabled.
+      if ($form_state['values']['autologout_role_' . $key]) {
+        $timeout = $form_state['values']['autologout_role_' . $key . '_timeout'];
+        if(!autologout_timeout_validate($timeout, $max_timeout)){
+          form_set_error($key . 'timeout', t('%role timeout must be an integer greater than 60, and less then %max.', array('%role' => $role,'%max' => $max_timeout)));
+        }
+      }
     }
   }
   $timeout = $form_state['values']['autologout_timeout'];
-  // validate timeout
-  
+
+  // Validate timeout.
   if (!is_numeric($timeout) || ((int)$timeout != $timeout) || $timeout < 60 || $timeout > $max_timeout) {
     form_set_error('autologout_timeout', t('The timeout must be an integer greater than 60, and less then %max.', array('%max' => $max_timeout)));
   }
-  
-  // ensure message is plain text
+
+  // Ensure message is plain text.
   $form_state['values']['autologout_message'] = check_plain($form_state['values']['autologout_message']);
 }
diff --git a/autologout.module b/autologout.module
index 75bea1a..d56636d 100644
--- a/autologout.module
+++ b/autologout.module
@@ -107,16 +107,10 @@ function theme_autologout_render_table($variables) {
  * Checks to see if timeout threshold is outside max/min values. Only done here
  * to centrilize and stop repeated code. Hard coded min, configurable max.
  */
-function autologout_timeout_validate($timeout) {
-  $validate = FALSE;
-  $max = variable_get('max_timeout', '172800');
-  if ($timeout < 60 || $timeout > $max || !is_numeric($timeout)) { // Less then 60, greater then max and is numaric.
-    $validate = FALSE;
-  }
-  else{
-    $validate = TRUE;
-  }
-  return $validate;
+function autologout_timeout_validate($timeout, $max) {
+  $valid = ($timeout >= 60 && $timeout <= $max && is_numeric($timeout));
+
+  return $valid;
 }
 
 /**
@@ -254,8 +248,8 @@ function _autologout_get_role_timeout() {
 
   // Go through roles, get timeouts for each and return as array.
   foreach ($roles as $rid => $role) {
-   $timeout_role = variable_get('autologout_role_' . $rid . '_timeout', $default_timeout);
-   $role_timeout[$rid] = $timeout_role;
+    $timeout_role = variable_get('autologout_role_' . $rid . '_timeout', $default_timeout);
+    $role_timeout[$rid] = $timeout_role;
   }
   return $role_timeout;
 }
