diff --git a/smartqueue.module b/smartqueue.module
index 4ad615d..c3b1228 100644
--- a/smartqueue.module
+++ b/smartqueue.module
@@ -29,7 +29,7 @@ function smartqueue_taxonomy_nodequeue_form($queue, &$form) {
     '#title' => t('Assume parent term for hierarchical vocabs'),
     '#description' => t("Instead of using the node's terms for nodequeue assignment use the top-most parents of a term. This has no effect if there in non-hierarchical vocabularies."),
     '#default_value' => isset($queue->use_parents) ? $queue->use_parents : 0,
-  );  
+  );
 
   $form['subqueue_title'] = array(
     '#type' => 'textfield',
@@ -278,25 +278,28 @@ function smartqueue_taxonomy($op, $type, $array = NULL) {
  * Get the top-level parents of the given taxonomy terms.
  *
  * @param $tids, an array of taxonomy IDs
- * 
- * @return an array of taxonomy IDs 
+ * @return an array of taxonomy IDs
  */
 function smartqueue_taxonomy_get_parents($tids) {
   if ($tids) {
-    $placeholders = db_placeholders($tids);
-    $result = db_query(db_rewrite_sql("SELECT t.tid, t.* FROM {term_data} t INNER JOIN {term_hierarchy} h ON h.parent = t.tid WHERE h.tid IN ($placeholders) ORDER BY weight, name", 't', 'tid'), $tids);
-    $parents = array();
-    // this will filter out duplicates.
-    while ($parent = db_fetch_object($result)) {
-      $parents[$parent->tid] = $parent->tid;
-    }
-    if (count($parents)) {
-      return smartqueue_taxonomy_get_parents($parents);
-    }
-    // we there weren't any matches, hand back the original tids.
-    else {
-      return $tids;
+    $top_level_tids = array();
+    foreach ($tids as $tid) {
+      $result = db_query(db_rewrite_sql("SELECT t.tid, t.* FROM {term_data} t INNER JOIN {term_hierarchy} h ON h.parent = t.tid WHERE h.tid = %d ORDER BY weight, name", 't', 'tid'), $tid);
+      $parents = array();
+      // This will filter out some duplicates.
+      while ($parent = db_fetch_object($result)) {
+        $parents[$parent->tid] = $parent->tid;
+      }
+      if (count($parents)) {
+        $parent_tid = smartqueue_taxonomy_get_parents($parents);
+        $top_level_tids = array_merge($parent_tid, $top_level_tids);
+      }
+      // When there aren't any matches, hand back the original tids.
+      else {
+        $top_level_tids[] = $tid;
+      }
     }
+    return array_unique($top_level_tids);
   }
   else {
     return array();
