diff --git a/wikitools.admin.inc b/wikitools.admin.inc
index 6bbf85a..7627eb6 100644
--- a/wikitools.admin.inc
+++ b/wikitools.admin.inc
@@ -116,30 +116,6 @@ function wikitools_page_duplicates() {
   $output = '';
   $found_nodes = FALSE;
 
-  list($select_query, $count_query, $arguments) = _wikitools_duplicate_nodes_query();
-  if ($select_query) {
-    $nodes_per_page = variable_get('default_nodes_main', 10);
-
-    // Grab all nodes that have the same title
-    $result = pager_query($select_query, $nodes_per_page, 0, $count_query, $arguments);
-    foreach ($result as $node) {
-      $output .= node_view(node_load($node->nid), 1);
-      $found_nodes = TRUE;
-    }
-  }
-
-  if ($found_nodes) {
-    $output .= theme('pager', array('tags' => NULL));
-  }
-
-  // Return a nice listing of all the duplicate nodes
-  return $output;
-}
-
-/**
- * Create queries to find nodes with duplicate titles.
- */
-function _wikitools_duplicate_nodes_query() {
   $node_types = array_values(wikitools_node_types());
   if (count($node_types)) {
     // Make sure we deal with various title equalities
@@ -155,10 +131,29 @@ function _wikitools_duplicate_nodes_query() {
     }
 
     // Grab all nodes that have the same title
-    $from_part = 'FROM {node} n1, {node} n2 WHERE LOWER(' . $n1_title . ') = LOWER(' . $n2_title . ') AND n1.nid != n2.nid AND n1.type IN(:type) AND n2.type IN(:type)';
-    $select_query = 'SELECT DISTINCT(n1.nid), n1.title ' . $from_part . ' ORDER BY n1.title ASC';
-    $count_query = 'SELECT COUNT(DISTINCT(n1.nid)) ' . $from_part;
-    return array($select_query, $count_query, array(':type' => $node_types));
+    $result = db_select('node', 'n1')
+      ->extend('PagerDefault')
+      ->fields('n1', array('nid'))
+      ->join('node', 'n2')
+      ->where('LOWER(' . $n1_title . ') = LOWER(' . $n2_title . ')')
+      ->condition('n1.nid', 'n2.nid', '<>')
+      ->condition('n1.type', $node_types, 'IN')
+      ->condition('n2.type', $node_types, 'IN')
+      ->orderBy('n1.title', 'ASC')
+      ->limit(variable_get('default_nodes_main', 10))
+      ->distinct()
+      ->execute();
+
+    foreach ($result as $node) {
+      $output .= node_view(node_load($node->nid), 1);
+      $found_nodes = TRUE;
+    }
   }
-  return array(NULL, NULL, NULL);
+
+  if ($found_nodes) {
+    $output .= theme('pager', array('tags' => NULL));
+  }
+
+  // Return a nice listing of all the duplicate nodes
+  return $output;
 }
