diff --git a/session_expire.module b/session_expire.module
index 3d6119b..0117e82 100644
--- a/session_expire.module
+++ b/session_expire.module
@@ -15,6 +15,8 @@ if(!defined('SESSION_EXPIRE_LAST'))
   define('SESSION_EXPIRE_LAST', 'session_expire_last');
 if(!defined('SESSION_EXPIRE_MAX_DELETIONS'))
   define('SESSION_EXPIRE_MAX_DELETIONS', 'session_expire_max_deletions');
+if(!defined('SESSION_EXPIRE_INTERVAL'))
+  define('SESSION_EXPIRE_INTERVAL', 'session_expire_interval');
 
 /**
  * Implements hook_menu().
@@ -76,6 +78,16 @@ function session_expire_settings() {
     '#description'   => t('Limit the number of sessions deleted during each invocation of the cron job by this amount. This is important if your sessions table is very large (e.g. more than 10,000 rows) because the job may run for a long time. One strategy is to use <a href="!url">Elysia Cron</a> to manage the frequency of execution of your cron jobs and set session_expire_cron to run hourly with this value set relatively low (1000 should be ok on most servers).', array('!url' => 'http://drupal.org/project/elysia_cron'))
   );
 
+  $interval = drupal_map_assoc(array(0, 7200, 10800, 21600, 43200, 86400, 172800, 259200, 604800), 'format_interval');
+  $interval['0'] = t('Everytime');
+  $form[SESSION_EXPIRE_INTERVAL] = array(
+    '#type'          => 'select',
+    '#title'         => t('Cron Interval'),
+    '#default_value' => variable_get(SESSION_EXPIRE_INTERVAL, 86400),
+    '#options'       => $interval,
+    '#description'   => t('Run the cleanup at the specified interval. This tells Drupal how often to run the cleanup. On a busy site, you want that to be more frequent (e.g. every day at a minimum). You don\'t want it to be too frequent though (e.g. every hour), as it can tie up the sessions table for a long time. Cron must be configured to run more frequently than the value you chose here.')
+  );
+
   return system_settings_form($form);
 }
 
@@ -105,11 +117,33 @@ function session_expire_cron() {
       $query->condition('uid', '0', '=');
     }
 
-    // Delete the sessions
+    // $max_deletions is way to prevent clearing out a huge amount of sessions.
+    // Current implementation un-pops the latest ones starting just before $timestamp.
+    // Better way => use Drupal Queues ?
+    // Set SESSION_EXPIRE_MAX_DELETIONS to 0 for removing all session before $timestamp.
     $max_deletions = (int) variable_get(SESSION_EXPIRE_MAX_DELETIONS, 1000);
     if ($max_deletions > 0) {
-      $query->range(0, $max_deletions);
+      // Define the latest min_timestamp existing for $max_deletions sessions
+      $max_query = db_select('sessions', 's')
+        ->fields('s', array('timestamp'))
+        ->condition('timestamp', $timestamp, '<');
+
+      if (!$mode) {
+        // On MySQL, adding this condition triggers a filesort. This can be an issue on very big tables.
+        $max_query->condition('uid', '0', '=');
+      }
+      // Order by timestamp, and grab the first $max_deletions
+      $max_query->orderBy('timestamp', 'DESC')->range(0, $max_deletions);
+      // Take the lowest value of the range
+      $min_timestamp = array_pop($max_query->execute()->fetchCol());
+
+      // We actually got a timestamp, so use it.
+      if (isset($min_timestamp)) {
+        $query->condition('timestamp', array($min_timestamp, $timestamp), 'BETWEEN');
+      }
     }
+
+    // Delete the sessions
     $num_updated = $query->execute();
 
     // Write to the watchdog
