diff --git a/visitorinfo.module b/visitorinfo.module
index eb9a640..ed120e7 100644
--- a/visitorinfo.module
+++ b/visitorinfo.module
@@ -233,7 +233,8 @@ function visitorinfo_cron() {
   // create an array to store all empty ips (ip addresses with no geographic
   // information) or rows that need to be updated
   $empty_ips = array();
-  $nothing = '';
+  
+  $limit = variable_get('visitorinfo_update_ip_process_count', 100);
   
   // check if ip data should be updated
   $interval = variable_get('visitorinfo_update_ip_interval_days', 30);
@@ -241,19 +242,22 @@ function visitorinfo_cron() {
     // convert days to seconds
     $interval = $interval * 24 * 60 * 60;
     $last_updated_limit = time() - $interval;
-    $result = db_query("SELECT csid, ip FROM {visitorinfo} v WHERE v.city = '%s' OR last_updated < %d", $nothing, $last_updated_limit);
+    $sql = "SELECT    csid, ip
+            FROM      {visitorinfo} v
+            WHERE     v.city = ''
+            OR        last_updated < %d
+            ORDER BY  last_updated ASC";
+    $result = db_query_range($sql, $last_updated_limit, 0, $limit);
   }
   else {
     // otherwise only take empty ips
-    $result = db_query("SELECT csid, ip FROM {visitorinfo} v WHERE v.city = '%s' ", $nothing);
+    $result = db_query_range("SELECT csid, ip FROM {visitorinfo} v WHERE v.city = '%s'", $nothing, 0, $limit);
   }
+  
+  // loop through result set and call _visitorinfo_get_location($ip, $rec_num) for each
   while ($data = db_fetch_object($result)) {
     $empty_ips["$data->csid"] = $data->ip;
-  }
-  
-  // loop through array and call _visitorinfo_get_location($ip, $rec_num) for each
-  foreach ($empty_ips as $rec_num => $ip) {
-    _visitorinfo_get_location($ip, $rec_num);
+    _visitorinfo_get_location($data->ip, $data->csid);
     //1000000 = 1 sec
     // ipinfodb.com has a limit of 2 hits per second
     usleep(500000);
@@ -434,6 +438,15 @@ function visitorinfo_settings() {
       '#default_value' => variable_get('visitorinfo_update_ip_interval_days', 30),
       '#size' => '10',
     );
+    
+    $form['visitorinfo_update_ip']['visitorinfo_update_ip_process_count'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Number of records to update'),
+      '#description' => t('The number of records to update on each cron run. Only useful if <em>Update interval</em> is not 0. You can diminish this if you encounter problems with cron. Note the processing of each record will take at a bit more than half a second and that the maximum execution time of cron is set to 240 seconds.'),
+      '#default_value' => variable_get('visitorinfo_update_ip_process_count', 100),
+      '#size' => '10',
+    );
+    
     return system_settings_form($form);
 }  
 
