diff --git a/term_ref_autocomplete/term_ref_autocomplete.pages.inc b/term_ref_autocomplete/term_ref_autocomplete.pages.inc
index 023aceb..d4749dd 100644
--- a/term_ref_autocomplete/term_ref_autocomplete.pages.inc
+++ b/term_ref_autocomplete/term_ref_autocomplete.pages.inc
@@ -38,41 +38,44 @@ function term_ref_autocomplete_callback($field_name, $raw_tags_typed = '') {
       $vids[] = $vocabularies[$tree['vocabulary']]->vid;
     }
 
-    $query = db_select('taxonomy_term_data', 't');
-    $query->addTag('translatable');
-    $query->addTag('term_access');
+    if (strrchr($raw_tags_typed, ',') == FALSE || !empty($tids)) {
 
-    // Do not select already entered terms.
-    if (!empty($tags_typed)) {
-      $query->condition('t.tid', $tids, 'NOT IN');
-    }
-    // Select rows that match by term name.
-    $tags_return = $query
-      ->fields('t', array('tid', 'name'))
-      ->condition('t.vid', $vids)
-      ->condition('t.name', '%' . db_like($tag_last) . '%', 'LIKE')
-      ->range(0, 10)
-      ->execute()
-      ->fetchAllKeyed();
+      $query = db_select('taxonomy_term_data', 't');
+      $query->addTag('translatable');
+      $query->addTag('term_access');
+
+      // Do not select already entered terms.
+      if (!empty($tags_typed)) {
+        $query->condition('t.tid', $tids, 'NOT IN');
+      }
+      // Select rows that match by term name.
+      $tags_return = $query
+        ->fields('t', array('tid', 'name'))
+        ->condition('t.vid', $vids)
+        ->condition('t.name', '%' . db_like($tag_last) . '%', 'LIKE')
+        ->range(0, 10)
+        ->execute()
+        ->fetchAllKeyed();
 
-    $prefix = count($tags_typed) ? drupal_implode_tags($tags_typed) . ', ' : '';
+      $prefix = count($tags_typed) ? drupal_implode_tags($tags_typed) . ', ' : '';
 
-    foreach ($tags_return as $tid => $name) {
-      $ancestors = array_reverse(taxonomy_get_parents_all($tid));
-      $term_tmp = &$term_matches;
-      foreach ($ancestors as $ancestor) {
-        $n = $ancestor->name;
-        // Term names containing commas or quotes must be wrapped in quotes.
-        if (strpos($n, ',') !== FALSE || strpos($n, '"') !== FALSE) {
-          $n = '"' . str_replace('"', '""', $n) . '"';
-        }
-        $term_tmp[$ancestor->tid]['display'] = $prefix . $n . '[tid:' . $ancestor->tid . ']';
-        $term_tmp[$ancestor->tid]['position'] = count($tags_typed);
-        $term_tmp[$ancestor->tid]['name'] = $ancestor->name;
-        if (!isset($term_tmp[$ancestor->tid]['children'])) {
-          $term_tmp[$ancestor->tid]['children'] = array();
+      foreach ($tags_return as $tid => $name) {
+        $ancestors = array_reverse(taxonomy_get_parents_all($tid));
+        $term_tmp = &$term_matches;
+        foreach ($ancestors as $ancestor) {
+          $n = $ancestor->name;
+          // Term names containing commas or quotes must be wrapped in quotes.
+          if (strpos($n, ',') !== FALSE || strpos($n, '"') !== FALSE) {
+            $n = '"' . str_replace('"', '""', $n) . '"';
+          }
+          $term_tmp[$ancestor->tid]['display'] = $prefix . $n . '[tid:' . $ancestor->tid . ']';
+          $term_tmp[$ancestor->tid]['position'] = count($tags_typed);
+          $term_tmp[$ancestor->tid]['name'] = $ancestor->name;
+          if (!isset($term_tmp[$ancestor->tid]['children'])) {
+            $term_tmp[$ancestor->tid]['children'] = array();
+          }
+          $term_tmp = &$term_tmp[$ancestor->tid]['children'];
         }
-        $term_tmp = &$term_tmp[$ancestor->tid]['children'];
       }
     }
   }
