diff --git a/cps.module b/cps.module
index 828b0a5..c58b37a 100644
--- a/cps.module
+++ b/cps.module
@@ -920,39 +934,43 @@ function cps_add_untracked_entities($changeset_id, $entity_type, $start = 0, $li
   $tracked = cps_get_tracked_entities($changeset_id);
   $info = entity_get_info($entity_type);
 
-  $entity_query = new EntityFieldQuery();
+  $query = db_select($info['base table'], 'base')
+    ->fields('base', array($info['entity keys']['id'], $info['entity keys']['revision']))
+    ->orderBy($info['entity keys']['id'], 'ASC')
+    ->condition($info['entity keys']['id'], $start, '>=')
+    ->range(0, $limit);
   if (!empty($tracked[$entity_type])) {
-    $entity_query->entityCondition('entity_id', $tracked[$entity_type], 'NOT IN');
+    $query->condition('base.' . $info['entity keys']['id'], $tracked[$entity_type], 'NOT IN');
   }
-  $results = $entity_query
-    ->entityCondition('entity_type', $entity_type)
-    ->entityOrderBy('entity_id', 'ASC')
-    ->range($start, $limit)
-    ->execute();
+
+  $result = $query->execute();
 
   // Reset the changeset
   cps_override_changeset(NULL);
-  if (!empty($results[$entity_type])) {
-    $query = db_insert('cps_entity')
-      ->fields(array(
-        'entity_type',
-        'entity_id',
-        'revision_id',
-        'changeset_id',
-        'published',
-      ));
-    foreach ($results[$entity_type] as $entity) {
-      $query->values(array(
-        'entity_type' => $entity_type,
-        'entity_id' => $entity->{$info['entity keys']['id']},
-        'revision_id' => $entity->{$info['entity keys']['revision']},
-        'changeset_id' => $changeset_id,
-        'published' => 1,
-      ));
-    }
+  $query = db_insert('cps_entity')
+    ->fields(array(
+      'entity_type',
+      'entity_id',
+      'revision_id',
+      'changeset_id',
+      'published',
+    ));
+
+  $last = 0;
+  foreach ($result as $record) {
+    $query->values(array(
+      'entity_type' => $entity_type,
+      'entity_id' => $record->{$info['entity keys']['id']},
+      'revision_id' => $record->{$info['entity keys']['revision']},
+      'changeset_id' => $changeset_id,
+      'published' => 1,
+    ));
+    $last = $record->{$info['entity keys']['id']};
+  }
+  if ($last) {
     $query->execute();
     // Return the last touched entity ID.
-    return max(array_keys($results[$entity_type]));
+    return $last;
   }
 }
 
