diff --git a/term_ref_autocomplete.pages.inc b/term_ref_autocomplete.pages.inc
index 023aceb..17ba7fb 100644
--- a/term_ref_autocomplete.pages.inc
+++ b/term_ref_autocomplete.pages.inc
@@ -43,7 +43,7 @@ function term_ref_autocomplete_callback($field_name, $raw_tags_typed = '') {
     $query->addTag('term_access');
 
     // Do not select already entered terms.
-    if (!empty($tags_typed)) {
+    if (!empty($tids)) {
       $query->condition('t.tid', $tids, 'NOT IN');
     }
     // Select rows that match by term name.
