diff --git a/user_restrictions.api.php b/user_restrictions.api.php
index 1eb175a..e5f4dd3 100755
--- a/user_restrictions.api.php
+++ b/user_restrictions.api.php
@@ -27,7 +27,7 @@ function hook_user_restrictions_alter(&$denied, &$error, &$context) {
  * Allows modules to give information about the implemented restrictions.
  *
  * @param $context
- *   An array containing the ID of the required information.
+ *   A string containing the ID of the required information.
  */
 function hook_user_restrictions_info($context) {
 }
diff --git a/user_restrictions.classes.inc b/user_restrictions.classes.inc
index 4185e3a..a4cb2b9 100644
--- a/user_restrictions.classes.inc
+++ b/user_restrictions.classes.inc
@@ -102,9 +102,10 @@ class UserRestrictions {
   }
 
   public static function exists($array) {
+    $new_array = array (':type'=>$array['type'], ':mask'=>$array['mask'],);
     $query = db_select('user_restrictions', 'ur')
     ->fields('ur', array('urid'))
-    ->where('type = :type AND LOWER(:mask) = LOWER(mask)', $array);
+    ->where('type = :type AND LOWER(:mask) = LOWER(mask)', $new_array);
 
     if (isset($array['subtype'])) {
       $query->condition('subtype', $array['subtype']);
@@ -121,14 +122,16 @@ class UserRestrictions {
 
   public static function deleteExpired() {
     return db_delete('user_restrictions')
-    ->condition('expire', REQUEST_TIME, '<=')
+    ->condition(db_and()
+      ->condition('expire', REQUEST_TIME, '<=')
+      ->condition('expire', 0, '>'))
     ->execute();
   }
 
   public static function getInstance($id = '') {
     if ($id) {
       $instance = db_query('SELECT * FROM {user_restrictions} WHERE urid = :urid', array(':urid' => $id), array('fetch' => 'UserRestrictions'))
-      ->fetchObject();
+      ->fetch();
     }
     else {
       $instance = new UserRestrictions();
@@ -137,21 +140,26 @@ class UserRestrictions {
     return empty($instance) ? FALSE : $instance;
   }
 
-  public static function getRestrictionTable($header) {
+  public static function getRestrictionTable($header, $destination) {
     $access_types = self::getTypeOptions();
+    $access_statuses = self::getStatusOptions();
     $rules = db_select('user_restrictions', 'ur')
-    ->fields('ur', array('urid', 'type', 'status', 'mask'))
-    ->condition('expire', 0)
+    ->fields('ur', array('urid', 'type', 'status', 'mask', 'expire'))
+    ->condition(db_or()
+      ->condition('expire', REQUEST_TIME, '>=')
+      ->condition('expire', 0))
     ->extend('PagerDefault')
     ->limit(50)
     ->extend('TableSort')
     ->orderByHeader($header)
     ->execute();
 
+    $rows = array();
     foreach ($rules as $rule) {
-      $rows[$rule->urid]['status'] = $rule->status ? t('allow') : t('deny');
+      $rows[$rule->urid]['status'] = $access_statuses[$rule->status];
       $rows[$rule->urid]['type'] = $access_types[$rule->type];
       $rows[$rule->urid]['mask'] = check_plain($rule->mask);
+      $rows[$rule->urid]['expire'] = $rule->expire ? format_date($rule->expire) : t('never');
       $rows[$rule->urid]['operations'] = array(
         'data' => array(
           '#theme' => 'links__user_restrictions_ui_rule_operations',
@@ -172,10 +180,12 @@ class UserRestrictions {
         ),
       );
     }
+    
+    return $rows;
   }
 
   public static function getStatusOptions() {
-    $context = array('status options');
+    $context = 'status options';
     $info = module_invoke_all('user_restrictions_info', $context);
     drupal_alter('user_restrictions_info', $info, $context);
 
@@ -183,7 +193,7 @@ class UserRestrictions {
   }
 
   public static function getTypeOptions() {
-    $context = array('type options');
+    $context = 'type options';
     $info = module_invoke_all('user_restrictions_info', $context);
     drupal_alter('user_restrictions_info', $info, $context);
 
@@ -196,7 +206,7 @@ class UserRestrictions {
     if (!empty($this->urid)) {
       $primary_keys[] = 'urid';
     }
-
+    
     return drupal_write_record('user_restrictions', clone $this, $primary_keys);
   }
 }
diff --git a/user_restrictions.module b/user_restrictions.module
index 5b850e9..999b5f8 100755
--- a/user_restrictions.module
+++ b/user_restrictions.module
@@ -76,12 +76,12 @@ function user_restrictions_permission() {
 function user_restrictions_user_restrictions_alter(&$denied, &$error, $context) {
   if ($context['type'] == 'mail' && $denied) {
     $error['field'] = 'mail';
-    $error['message'] = t('The email address %email is reserved, and cannot be used.', array('%email' => $mask));
+    $error['message'] = t('The email address %email is not allowed.', array('%email' => $context['mask']));
   }
 
   if ($context['type'] == 'name' && $denied) {
     $error['field'] = 'name';
-    $error['message'] = t('The name %name is a reserved username, and cannot be used.', array('%username' => $mask));
+    $error['message'] = t('The name %name is not allowed.', array('%name' => $context['mask']));
   }
 }
 
@@ -113,8 +113,8 @@ function user_restrictions_user_restrictions_info($id, $arg1 = NULL, $arg2 = NUL
 
     case 'status options':
       return array(
-        t('Allowed'),
         t('Denied'),
+        t('Allowed'),
       );
 
     case 'type options':
@@ -122,6 +122,13 @@ function user_restrictions_user_restrictions_info($id, $arg1 = NULL, $arg2 = NUL
         'mail' => t('Email'),
         'name' => t('Username'),
       );
+
+    default:
+      watchdog('user_restrictions', 
+               'got an unexpected id value in user_restrictions_user_restrictions_info ' . print_r($id, TRUE),
+               NULL,
+               WATCHDOG_ERROR
+              );
   }
 }
 
@@ -140,7 +147,8 @@ function user_restrictions_login_form_validate($form, &$form_state) {
       }
 
       $error = UserRestrictions::check($form_state, 'login');
-      if ($error) {
+
+      if ($error['message']) {
         form_set_error($error['field'], $error['message']);
       }
     }
@@ -159,7 +167,7 @@ function user_restrictions_user_profile_form_validate($form, &$form_state) {
   }
 
   $error = UserRestrictions::check($form_state, 'profile');
-  if ($error) {
+  if ($error['message']) {
     form_set_error($error['field'], $error['message']);
   }
 }
@@ -171,7 +179,7 @@ function user_restrictions_user_profile_form_validate($form, &$form_state) {
  */
 function user_restrictions_user_register_form_validate($form, &$form_state) {
   $error = UserRestrictions::check($form_state, 'register');
-  if ($error) {
+  if ($error['message']) {
     form_set_error($error['field'], $error['message']);
   }
 }
diff --git a/user_restrictions_ui.admin.inc b/user_restrictions_ui.admin.inc
index a713264..097ed87 100644
--- a/user_restrictions_ui.admin.inc
+++ b/user_restrictions_ui.admin.inc
@@ -11,7 +11,7 @@
  * @see user_restrictions_ui_delete_rule_form_submit()
  * @ingroup forms
  */
-function user_restrictions_ui_delete_rule_form($form_state, $rule) {
+function user_restrictions_ui_delete_rule_form($form, &$form_state, $rule) {
   $access_types = $rule->getTypeOptions();
   $form = array('#rule' => serialize($rule));
 
@@ -49,7 +49,7 @@ function user_restrictions_ui_delete_rule_form_submit($form, &$form_state) {
  */
 function user_restrictions_ui_edit_rule_form($form, &$form_state, $rule = NULL) {
   if (!isset($rule)) {
-    $rule = UserRestrictions::getInstance();
+    $rule = UserRestrictions::getInstance($rule);
   }
 
   $form['#rule'] = serialize($rule);
@@ -64,7 +64,7 @@ function user_restrictions_ui_edit_rule_form($form, &$form_state, $rule = NULL)
   $form['type'] = array(
     '#type' => 'radios',
     '#title' => t('Rule type'),
-    '#default_value' => $rule->type,
+    '#default_value' => $rule->type ? $rule->type : 'mail',
     '#options' => $rule->getTypeOptions(),
   );
 
@@ -77,6 +77,22 @@ function user_restrictions_ui_edit_rule_form($form, &$form_state, $rule = NULL)
     '#description' => t('%ampersand: Matches any number of characters, even zero characters.<br />%underscore: Matches exactly one character.', array('%ampersand' => '%', '%underscore' => '_')),
     '#required' => TRUE,
   );
+  
+  $expire_options = array(0 => t('Never'));
+  if ($rule->expire) {
+    $expire_options['-1'] = format_interval($rule->expire - REQUEST_TIME);
+    $default_expire = '-1';
+  }
+  else {
+    $default_expire = 0;
+  }
+  $form['expire'] = array(
+    '#type' => 'select',
+    '#title' => t('Expire'),
+    '#default_value' => $default_expire,
+    '#options' => $expire_options + drupal_map_assoc(array(3600, 10800, 21600, 32400, 43200, 86400, 172800, 259200, 604800, 1209600, 2419200, 4838400, 9676800), 'format_interval'),
+    //'#description' => t(''),
+  );
 
   $form['submit'] = array(
     '#type' => 'submit',
@@ -97,9 +113,9 @@ function user_restrictions_ui_edit_rule_form_validate($form, &$form_state) {
 
   // Verify if there are other rules of the same type with the same mask.
   $rule = unserialize($form['#rule']);
-  if ($rule->exists($form_state['values'])) {
+  if ($rule->exists($form_state['values']) && !$rule->urid) {
     form_set_error('mask', t('The mask value has been already used in a rule.'));
-  }
+  }  
 }
 
 /**
@@ -107,7 +123,17 @@ function user_restrictions_ui_edit_rule_form_validate($form, &$form_state) {
  */
 function user_restrictions_ui_edit_rule_form_submit($form, &$form_state) {
   $rule = unserialize($form['#rule']);
+
+  //set the values from the form into the object
+  $rule->status = $form_state['values']['status'];
+  $rule->type = $form_state['values']['type'];
+  $rule->mask = $form_state['values']['mask'];
+  if ($form_state['values']['expire'] != -1) {
+    $rule->expire = $rule->expire ?  $rule->expire + REQUEST_TIME : 0;
+  }
   $rule->save();
+  
+  drupal_set_message(t('The access rule has been saved.'));
 }
 
 /**
@@ -124,9 +150,10 @@ function user_restrictions_ui_overview_form($form, &$form_state) {
     'status' => array('data' => t('Access type'), 'field' => 'status', 'sort' => 'desc'),
     'type' => array('data' => t('Rule type'), 'field' => 'type'),
     'mask' => array('data' => t('Mask'), 'field' => 'mask'),
+    'expire' => array('data' => t('Expire'), 'field' => 'expire'),
     'operations' => array('data' => t('Operations'), 'colspan' => 2)
   );
-  $rows = UserRestrictions::getRestrictionTable($header);
+  $rows = UserRestrictions::getRestrictionTable($header, $destination);
 
   $form['rules'] = array(
     '#theme' => 'table',
@@ -142,8 +169,6 @@ function user_restrictions_ui_overview_form($form, &$form_state) {
       '#type' => 'fieldset',
       '#title' => t('Check rules'),
       '#attributes' => array('class' => array('container-inline')),
-      '#collapsible' => TRUE,
-      '#collapsed' => TRUE,
     );
 
     $form['check_rules']['value'] = array(
@@ -178,11 +203,8 @@ function user_restrictions_ui_overview_form($form, &$form_state) {
  * @see user_restrictions_ui_check_email_submit()
  */
 function user_restrictions_ui_check_email_validate($form, &$form_state) {
-  $bool = (
-    !empty($form_state['values']['value']) &&
-    !valid_email_address($form_state['values']['value'])
-  );
-  if ($bool) {
+  if (empty($form_state['values']['value'])
+      || !valid_email_address($form_state['values']['value'])) {
     form_set_error('value',t('The entered value is not a valid email address.'));
   }
 }
@@ -194,15 +216,14 @@ function user_restrictions_ui_check_email_validate($form, &$form_state) {
  * @see user_restrictions_ui_check_email_validate()
  */
 function user_restrictions_ui_check_email_submit($form, &$form_state) {
-  if (!empty($form_state['values']['value'])) {
-    if ($error = UserRestrictions::check($form_state, 'check_mail')) {
-      drupal_set_message($error['message']);
-    }
-    else {
-      drupal_set_message(
-        t('The e-mail address %mail is allowed.', array('%mail' => $form_state['values']['value']))
-      );
-    }
+  $error = UserRestrictions::check($form_state, 'check_mail');
+  if ($error['message'] != '') {
+    drupal_set_message($error['message']);
+  }
+  else {
+    drupal_set_message(
+      t('The e-mail address %mail is allowed.', array('%mail' => $form_state['values']['value']))
+    );
   }
 }
 
@@ -212,14 +233,13 @@ function user_restrictions_ui_check_email_submit($form, &$form_state) {
  * @see user_restrictions_ui_overview_form()
  */
 function user_restrictions_ui_check_username_submit($form, &$form_state) {
-  if (!empty($form_state['values']['value'])) {
-    if ($error = UserRestrictions::check($form_state, 'check_name')) {
-      drupal_set_message($error['message']);
-    }
-    else {
-      drupal_set_message(
-        t('The username %name is allowed.', array('%name' => $form_state['values']['value']))
-      );
-    }
+  $error = UserRestrictions::check($form_state, 'check_name');
+  if ($error['message'] != '') {
+    drupal_set_message($error['message']);
+  }
+  else {
+    drupal_set_message(
+      t('The username %name is allowed.', array('%name' => $form_state['values']['value']))
+    );
   }
 }
