diff --git a/session_expire.module b/session_expire.module
index a85800f..0324b9c 100644
--- a/session_expire.module
+++ b/session_expire.module
@@ -8,13 +8,15 @@
  */
 
 if(!defined('SESSION_EXPIRE_AGE'))
-  define('SESSION_EXPIRE_AGE',      'session_expire_age');
+  define('SESSION_EXPIRE_AGE',            'session_expire_age');
 if(!defined('SESSION_EXPIRE_MODE'))
-  define('SESSION_EXPIRE_MODE',     'session_expire_mode');
+  define('SESSION_EXPIRE_MODE',           'session_expire_mode');
 if(!defined('SESSION_EXPIRE_LAST'))
-  define('SESSION_EXPIRE_LAST', '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');
+  define('SESSION_EXPIRE_MAX_DELETIONS',  'session_expire_max_deletions');
+if(!defined('SESSION_EXPIRE_INTERVAL'))
+  define('SESSION_EXPIRE_INTERVAL',       'session_expire_interval');
 
 /**
  * Implements hook_menu().
@@ -105,11 +107,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
