diff --git a/references_dialog.module b/references_dialog.module
index 9ad6435..2d8af03 100644
--- a/references_dialog.module
+++ b/references_dialog.module
@@ -321,7 +321,7 @@ function references_dialog_process_widget(&$element) {
   if (count($dialog_links)) {
     // We add a div directly into the markup here since we really need it in order
     // to make sure the javascript works.
-    $element['#suffix'] = '<div class="dialog-links ' . $element['#id'] . '">' . theme('references_dialog_links', $dialog_links) . '</div>';
+    $element['#suffix'] = '<div class="dialog-links ' . $element['#id'] . '">' . theme('references_dialog_links', array('links' => $dialog_links)) . '</div>';
   }
   return $element;
 }
@@ -341,7 +341,7 @@ function references_dialog_build_element($element) {
   if (count($dialog_links)) {
     // We add a div directly into the markup here since we really need it in order
     // to make sure the javascript works.
-    $element['#suffix'] = '<div class="dialog-links ' . $element['#id'] . '">' . theme('references_dialog_links', $dialog_links) . '</div>';
+    $element['#suffix'] = '<div class="dialog-links ' . $element['#id'] . '">' . theme('references_dialog_links', array('links' => $dialog_links)) . '</div>';
   }
   return $element;
 }
@@ -691,6 +691,24 @@ function references_dialog_get_admin_path($entity_type, $op, $bundle = NULL, $en
  * Theme function for theming the links for opening
  * the references dialog.
  */
-function theme_references_dialog_links($links) {
-  return theme('links', array('links' => $links, 'attributes' => array('class' => 'references-dialog-links')));
+function theme_references_dialog_links($variables) {
+  $links = array_filter($variables);
+  $ctools_links_themed = '';
+  if (module_exists('ctools') && count($links) > variable_get('references_dialog_links_threshold', 3)) {
+    $ctools_links = array();
+    $non_ctools_links = array();
+    foreach ($links as $link) {
+      switch (TRUE) {
+        case strpos($link['href'], 'references-dialog/search') === 0:
+          $non_ctools_links[] = $link;
+          break;
+
+        default:
+          $ctools_links[] = $link;
+          break;
+      }
+    }
+    $ctools_links_themed = theme('links__ctools_dropbutton', array('links' => $ctools_links, 'title' => t('Create'), 'attributes' => array('class' => array('references-dialog-links'))));
+  }
+  return $ctools_links_themed . theme('links', array('links' => $variables['links'], 'attributes' => array('class' => array('references-dialog-links'))));
 }
