diff --git a/expire.module b/expire.module
index 67d82a4..a10e752 100644
--- a/expire.module
+++ b/expire.module
@@ -119,7 +119,7 @@ function expire_comment_delete($comment) {
 
 /**
  * Implements hook_node_insert().
- * 
+ *
  * Acts on new nodes.
  */
 function expire_node_insert($node) {
@@ -133,7 +133,7 @@ function expire_node_insert($node) {
 
 /**
  * Implements hook_node_update().
- * 
+ *
  * Acts on node updates.
  */
 function expire_node_update($node) {
@@ -147,7 +147,7 @@ function expire_node_update($node) {
 
 /**
  * Implements hook_node_delete().
- * 
+ *
  * Acts on deletion of nodes.
  */
 function expire_node_delete($node) {
@@ -161,7 +161,7 @@ function expire_node_delete($node) {
 
 /**
  * Implements hook_node_revision_delete().
- * 
+ *
  * Acts on deletion of revisions.
  */
 function expire_node_revision_delete($node) {
@@ -258,7 +258,7 @@ function expire_votingapi_delete($votes) {
 function _expire_votingapi($votes) {
   foreach ($votes as $vote) {
     if ($vote['content_type'] == 'comment') {
-      $nid = db_result(db_query("SELECT nid FROM {comments} WHERE cid = %d", $vote['content_id']));
+      $nid = db_query("SELECT nid FROM {comments} WHERE cid = :cid", array(':cid' => $vote['content_id']))->fetchField();
       if (is_numeric($nid)) {
         $node = node_load($nid);
         if ($node) {
@@ -283,7 +283,7 @@ function _expire_votingapi($votes) {
  * @param $node
  *  node object
  */
-function expire_node(&$node) {
+function expire_node($node) {
   $paths = array();
 
   // Check node object
@@ -301,31 +301,17 @@ function expire_node(&$node) {
 
   // Get taxonomy terms and flush
   if (module_exists('taxonomy') && variable_get('expire_flush_node_terms', EXPIRE_FLUSH_NODE_TERMS)) {
-    // Get old terms from DB
-    $tids = expire_taxonomy_node_get_tids($node->nid);
-    // Get old terms from static variable
-    $terms = taxonomy_node_get_terms($node);
-    if (!empty($terms)) {
-      foreach ($terms as $term) {
-        $tids[$term->tid] = $term->tid;
-      }
-    }
-    // Get new terms from node object
-    if (!empty($node->taxonomy)) {
-      foreach ($node->taxonomy as $vocab) {
-        if (is_array($vocab)) {
-          foreach ($vocab as $term) {
-            $tids[$term] = $term;
-          }
-        }
+    $terms = array();
+    $info = field_info_fields();
+
+    foreach (field_info_instances('node', $node->type) as $name => $instance) {
+      if ($info[$name]['type'] == 'taxonomy_term_reference') {
+        $terms = array_merge($node->{$name}[$node->language], $node->original->{$name}[$node->language], $terms);
       }
     }
-    $filenames = array();
-    foreach ($tids as $tid) {
-      if (is_numeric($tid)) {
-        $term = taxonomy_get_term($tid);
-        $paths['term' . $tid] = taxonomy_term_path($term);
-      }
+
+    foreach ($terms as $term) {
+      $paths['term' . $term['tid']] = 'taxonomy/term/' . $term['tid'];
     }
   }
 
@@ -369,10 +355,10 @@ function expire_node(&$node) {
           $table = $info['table'];
           $column = $info['columns']['nid']['column'];
           $results = db_query("SELECT n.nid
-            FROM {%s} nr
+            FROM {$table} nr
             INNER JOIN {node} n USING (vid)
-            WHERE nr.%s = %d", $table, $column, $node->nid);
-          while ($nid = db_result($results)) {
+            WHERE nr.$column = :nid", array(':nid' => $node->nid));
+          foreach ($results->fetchCol() as $nid) {
             if (is_numeric($nid)) {
               $paths['referenceparent' . $nid] = 'node/'. $nid;
             }
@@ -484,22 +470,6 @@ function expire_get_menu_structure($menu, $found, $needle, $first, &$found_globa
 }
 
 /**
- * Return taxonomy terms given a nid.
- *
- * Needed because of a weird bug with CCK & node_load()
- *  http://drupal.org/node/545922
- */
-function expire_taxonomy_node_get_tids($nid) {
-  $vid = db_result(db_query("SELECT vid FROM {node} WHERE nid = %d", $nid));
-  $result = db_query(db_rewrite_sql("SELECT t.tid FROM {term_node} r INNER JOIN {term_data} t ON r.tid = t.tid INNER JOIN {vocabulary} v ON t.vid = v.vid WHERE r.vid = %d ORDER BY v.weight, t.weight, t.name", 't', 'tid'), $vid);
-  $tids = array();
-  while ($term = db_result($result)) {
-    $tids[] = $term;
-  }
-  return $tids;
-}
-
-/**
  * Finds all possible paths/redirects/aliases given the root path.
  *
  * @param $paths
@@ -598,7 +568,7 @@ function expire_path_redirect_load($where = array(), $args = array(), $sort = ar
   foreach ($where as $key => $value) {
     if (is_string($key)) {
       $args[] = $value;
-      $where[$key] = $key .' = '. (is_numeric($value) ? '%d' : "'%s'");
+      $where[$key] = $key .' = '. (is_numeric($value) ? '?' : '?');
     }
   }
 
@@ -688,14 +658,14 @@ function expire_get_base_urls(&$node) {
 function expire_get_domains(&$node) {
   $domains = array();
   if ($node->nid) {
-    $result = db_query("SELECT gid FROM {domain_access} WHERE nid = %d", $node->nid);
+    $result = db_query("SELECT gid FROM {domain_access} WHERE nid = :nid", array($node->nid));
     while ($row = db_fetch_array($result)) {
       $gid = $row['gid'];
       $domains[$gid] = $gid;
     }
   }
   elseif ($node->mail && $node->name) {
-    $result = db_query("SELECT domain_id FROM {domain_editor} WHERE uid = %d", $node->uid);
+    $result = db_query("SELECT domain_id FROM {domain_editor} WHERE uid = :uid", array($node->uid));
     while ($row = db_fetch_array($result)) {
       $gid = $row['domain_id'];
       $domains[$gid] = $gid;
