diff --git a/synonyms.module b/synonyms.module
index b17262c..b386394 100644
--- a/synonyms.module
+++ b/synonyms.module
@@ -7,7 +7,7 @@
 
 /**
  * Implements hook_taxonomy_vocabulary_insert().
- * 
+ *
  * Attach an instance of the synonym field to every
  * new vocabulary on creation.
  */
@@ -23,7 +23,7 @@ function synonyms_taxonomy_vocabulary_insert($vocabulary) {
 
 /**
  * Returns all synonyms for a given term id.
- * 
+ *
  *  @param $tid
  *   A term ID.
  *
@@ -31,27 +31,36 @@ function synonyms_taxonomy_vocabulary_insert($vocabulary) {
  *   An array containing all synonyms of the given term id.
  */
 function synonyms_get_synonyms($tid) {
+  $synonyms = array();
   if ($tid) {
-    return db_query('SELECT synonyms_synonym_value FROM {field_data_synonyms_synonym} WHERE entity_id = :tid', array(':tid' => $tid))->fetchCol();
-  }
-  else {
-    return array();
+    $term = taxonomy_term_load($tid);
+    $synonyms_synonym = field_view_field('taxonomy_term', $term, 'synonyms_synonym');
+    if (isset($synonyms_synonym['#items'])){
+      foreach ($synonyms_synonym['#items'] as $delta => $synonym) {
+        $synonyms[] = $synonym['value'];
+      }
+    }
   }
+  return $synonyms;
 }
 
 /**
  * Returns the term object that has the given string as a synonym.
- * 
+ *
  * @param $synonym
  *  A string containing the synonym to search for.
- *  
+ *
  * @return
- *  An array of term objects containing that synonym. 
+ *  An array of term objects containing that synonym.
  */
 function synonyms_get_synonym_root($synonym) {
-    $tids = db_query('SELECT tid FROM {field_data_synonyms_synonym} s, {taxonomy_term_data} t WHERE t.tid = s.entity_id AND s.synonyms_synonym_value = :name', array(':name' => $synonym))->fetchCol();
-    $terms = taxonomy_term_load_multiple($tids);
-    return $terms;
+  $query = new EntityFieldQuery;
+  $result = $query
+    ->entityCondition('entity_type', 'taxonomy_term')
+    ->fieldCondition('synonyms_synonym', 'value', $synonym, '=')
+    ->execute();
+
+  return isset($result['taxonomy_term']) ? $result['taxonomy_term'] : array();
 }
 
 /**
@@ -60,28 +69,19 @@ function synonyms_get_synonym_root($synonym) {
  * Ensures that synonyms are included when indexing a node
  */
 function synonyms_node_update_index($node) {
- // Get a list of all term reference fields attached to this node type
-  $term_reference_fields = db_query(
-    "SELECT fc.field_name
-     FROM {field_config_instance} fci
-     JOIN {field_config} fc ON fci.field_id = fc.id
-     WHERE fci.bundle = :type
-     AND fc.type = 'taxonomy_term_reference'", array(':type' => $node->type))->fetchCol();
+  #get the fields defenition of node type
+  $type_fields = field_info_instances('node');
 
   $synonyms = array();
-  // Loop through each vocabulary attached to this node type
-  foreach ($term_reference_fields as $term_reference_field) {
-    // Check if the node contains any taxonomy terms from this vocabulary
-    if ($node->nid > 0 && !empty($node->$term_reference_field)) {
-      // Get the vocabulary object
-      $taxonomy_tags = $node->$term_reference_field;
-      // Loop through each term attached to the node
-      foreach ($taxonomy_tags['und'] as $term) {
-        // Loop through each synonym of this term and add them to the array
-        foreach (synonyms_get_synonyms($term['tid']) as $synonym) {
-          $synonyms[] = $synonym;
+  foreach ($type_fields[$node->type] as $field_name => $field) {
+    $fieldinfos = field_info_field($field_name);
+    if ($fieldinfos['type'] == 'taxonomy_term_reference'){
+      $terms = field_view_field('node', $node, $field_name);
+      if (isset($terms['#items'])){
+        foreach ($terms['#items'] as $delta => $term) {
+          $synonyms = array_merge($synonyms, synonyms_get_synonyms($term['tid']));
         }
-      }      
+      }
     }
   }
   if (!empty($synonyms)) {
@@ -90,4 +90,4 @@ function synonyms_node_update_index($node) {
   else {
     return FALSE;
   }
-}
\ No newline at end of file
+}
