diff --git a/glossary.module b/glossary.module
index 58c9537..44d1f1c 100644
--- a/glossary.module
+++ b/glossary.module
@@ -402,7 +402,8 @@ function glossary_filter_glossary_process($text, $filter, $format, $langcode, $c
       $term_title = $term->description;
       $fragment = NULL;
       if ($term->nodes > 0) {
-        $linkto = taxonomy_term_path($term);
+        $uri = taxonomy_term_uri($term);
+        $linkto = $uri['path'];
       }
       elseif (!empty($vids) && (variable_get('glossary_click_option', 0) == 1)) {
         if (variable_get('glossary_hide_if_empty', 1) && empty($term_title)) {
@@ -514,6 +515,7 @@ function glossary_filter_glossary_process($text, $filter, $format, $langcode, $c
 
       // Replace term with the desired new HTML code.
       $terms_replace[] = array(
+        'name' => $term->name,
         'ins_before' => $ins_before,
         'ins_after' => $ins_after,
       );
@@ -582,37 +584,37 @@ function _glossary_insertlink($format, &$text, &$terms) {
   }
 
   // Find match candidates.
-  // @TODO: We don't have synonyms any more.
   foreach ($terms as $i => $term) {
-    foreach ($term['synonyms'] as $synonym) {
-      if (!$case_sensitive) {
-        $synonym = drupal_strtolower($synonym);
-      }
-      $offset = 0;
-      $first_match_found = FALSE;
-      while (($offset = $findfunc($searchtext, $synonym, $offset)) !== FALSE) {
-        $len = drupal_strlen($synonym);
-        $match = drupal_substr($text, $offset, $len);
-        // Only longer matches override shorter ones.
-        if (!isset($events[$offset]) || drupal_strlen($events[$offset]['match']) < drupal_strlen($match)) {
-          // Get synonym with case as in text.
-          $events[$offset] = array(
-            'type' => 'match',
-            'which' => $i,
-            'match' => $match,
-          );
-          if (!$replaceall) {
-            $first_match_found = TRUE;
-            break;
-          }
+    $term_name = $term['name'];
+    if (!$case_sensitive) {
+      $term_name = drupal_strtolower($term_name);
+    }
+
+    $offset = 0;
+    $first_match_found = FALSE;
+
+    while (($offset = $findfunc($searchtext, $term_name, $offset)) !== FALSE) {
+      $len = drupal_strlen($term_name);
+      $match = drupal_substr($text, $offset, $len);
+      // Only longer matches override shorter ones.
+      if (!isset($events[$offset]) || drupal_strlen($events[$offset]['match']) < drupal_strlen($match)) {
+        // Get synonym with case as in text.
+        $events[$offset] = array(
+          'type' => 'match',
+          'which' => $i,
+          'match' => $match,
+        );
+        if (!$replaceall) {
+          $first_match_found = TRUE;
+          break;
         }
-        $offset += $len;
-      }
-      // TODO: remove this if we want different synonyms of the same term to
-      // be matched independently as 'first matches'.
-      if ($first_match_found && !$replaceall) {
-        break;
       }
+      $offset += $len;
+    }
+    // TODO: remove this if we want different synonyms of the same term to
+    // be matched independently as 'first matches'.
+    if ($first_match_found && !$replaceall) {
+      break;
     }
   }
 
@@ -954,8 +956,9 @@ function theme_glossary_overview_item($variables) {
         $output .= "</div>\n";
       }
       else {
+        $uri = taxonomy_term_uri($term);
         $output .= '<div class="glossary-detailed-link">' .
-            l(t('Detailed definition of @term', array('@term' => $term->name)), taxonomy_term_path($term))
+          l(t('Detailed definition of @term', array('@term' => $term->name)), $uri['path'])
             . '</div>';
       }
     }
@@ -1146,31 +1149,37 @@ function _glossary_get_terms($format) {
       // Omit terms without a description. those are usually container terms.
       // If multilingual taxonomy is enabled only show terms in current or no
       // language.
-      $result = db_select('taxonomy_term_data', 'td');
-      // $result->leftJoin('taxonomy_index', 'ti');
-      $result->join('taxonomy_index', 'ti');
+      $query = db_select('taxonomy_term_data', 'td');
+      // $query->leftJoin('taxonomy_index', 'ti');
+      $query->join('taxonomy_index', 'ti');
 
-      $result->fields('td', array('tid', 'name'))
+      $query->fields('td', array('tid', 'name', 'description'))
           ->addExpression('COUNT(ti.nid)', 'nodes');
-      $result->condition('td.vid', $vid)
+      $query->condition('td.vid', $vid)
           ->groupBy('td.tid')
           ->groupBy('td.name')
           ->groupBy('td.description')
           ->orderBy('LENGTH(td.name)', 'DESC');
       if (module_exists('i18ntaxonomy')) {
         global $language;
-        $result->condition('td.language', array('', $language->language), 'IN');
+        $query->condition('td.language', array('', $language->language), 'IN');
       }
 
-      // $result->addTag('term_access');
-      $result->execute();
-      foreach ($result as $term) {
+      // $query->addTag('term_access');
+      $result = $query->execute();
+      while ($term = $result->fetchObject()) {
         if ($term->nodes) {
           // If there were any nodes attached, we need to
           // see if they were unpublished.
           // TODO Please convert this statement to the D7 database API syntax.
-          $unpubs = db_query(db_rewrite_sql("SELECT COUNT(n.nid) FROM {taxonomy_term_node} tn JOIN {node} n USING (nid) WHERE tn.tid=%d AND n.status=0"), $term->tid)->fetchField();
-          $term->nodes -= $unpubs;
+          //$unpubs = db_query(db_rewrite_sql("SELECT COUNT(n.nid) FROM {taxonomy_term_node} tn JOIN {node} n USING (nid) WHERE tn.tid=%d AND n.status=0"), $term->tid)->fetchField();
+          $query = db_select('taxonomy_index', 'ti')
+            ->condition('ti.tid', $term->tid, '=');
+          $query->addJoin('INNER', 'node', 'n', 'ti.nid = %alias.nid');
+          $query->condition('n.status', 0, '=');
+          $query->addExpression('COUNT(n.nid)', 'nodes');
+          $unpubs = $query->execute();
+          $term->nodes -= $unpubs->fetchField();
         }
 
         if ($term->description || $show_all) {
@@ -1198,7 +1207,7 @@ function _glossary_get_terms($format) {
  *   the term id to look up.
  * @param bool $one_way
  *   whether to do one-way or two-way relations.
- * 
+ *
  * @return array
  *   an array related-tid => related-name
  */
@@ -1224,7 +1233,7 @@ function glossary_get_related($tid, $key = 'tid', $one_way = FALSE) {
       // }, {taxonomy_term_data} t WHERE (t.tid = :(t.tid OR t.tid = :t.tid AND
       // (tid1 = :(tid1 OR tid2 = :tid2)AND t.tid != :t.tid ORDER BY weight,
       // name', array(':(t.tid' => 'tid1', ':t.tid' => 'tid2', ':(tid1' =>
-      // $qargs)); 
+      // $qargs));
       // foreach ($result as $term) {
       // $related[$term->$key] = $term;
       // }
