diff --git a/upload_replace.module b/upload_replace.module
index 0489f2d..7d1d644 100644
--- a/upload_replace.module
+++ b/upload_replace.module
@@ -15,60 +15,53 @@
 /**
  * Implementation of hook_file_update()
  */
-function upload_replace_file_update(&$new_file) {
+function upload_replace_file_update($new_file) {
   if (!$new_file->fid) {
     //Nothing to do if no fileid
     return;
   }
-  
   $desired_destination = preg_replace('/_[0-9]+\.(.*)$/', '.$1', $new_file->uri);
   $db_path = db_select('file_managed', 'f')
-    ->fields('f', array('uri', ))
+    ->fields('f', array('uri'))
     ->condition('fid', $new_file->fid)
     ->execute()
-    ->fetchField();
-  if ($db_path != $new_file->uri) {
+    ->fetchAssoc();
+  if ($db_path['uri'] != $new_file->uri) {
     //this happens when a reversion is being reverted
-    $next_good_filepath = file_destination($desired_destination, FILE_EXISTS_RENAME);
+    $next_good_uri = file_destination($desired_destination, FILE_EXISTS_RENAME);
     db_update('file_managed')
-      ->fields(array('uri' => $next_good_filepath))
+      ->fields(array('uri' => $next_good_uri))
       ->condition('fid', $new_file->fid)
       ->execute();
     $new_file->uri = $desired_destination;
   }
   else {
     //If the filename has be modified by adding a _0 value, or
-    //on certain situations the filepath will not match the filepath in the db, such as
+    //on certain situations the uri will not match the uri in the db, such as
     //when reverting a revision.  When reverting a revision change the filename as well
-    if (!strpos($new_file->uri, $new_file->uri)) {
-      //the filename is not in the filepath, so drupal must have added a "_0" before the extension
+    if (!strpos($new_file->uri, $new_file->filename)) {
+      //the filename is not in the uri, so drupal must have added a "_0" before the extension
       //find the file that is blocking this file from keeping the correct path
       $result = db_select('file_managed', 'f')
         ->fields('f')
         ->condition('uri', $desired_destination)
         ->execute();
       //@todo only one result is handled, should allow for multiple results
-      $is_blocked = false;
-      
       foreach ($result as $file) {
         $is_blocked = TRUE;
         $blocking_file = $file;
-        $tmp_destination = file_directory_temp() ."/$blocking_file->filename";
+        $tmp_destination = file_directory_temp()."/test_-".$blocking_file->fid."_-".$blocking_file->filename."";
       }
 
-      $old_destination = $db_path;
-
-      if ($old_destination == $desired_destination){
-        return;
-      }
+      $old_destination = $db_path['uri'];
       //Swap the files
       if ($is_blocked) {
-        //move the blocking file to a temporary location
+        //move the blocking file to a temparary location
         if (!file_unmanaged_move($desired_destination, $tmp_destination)) {
           drupal_set_message(t('The file %old could not be moved to %new', array('%old' => $desired_destination, '%new' => $tmp_destination)), 'error');
           return;
         }
-        //DRUPAL 7 no longer changes the source filepath during move
+        //DRUPAL 7 no longer changes the source uri during move
         //move blocking file was successful, update the DB
         db_update('file_managed')
           ->fields(array('uri' => $tmp_destination))
@@ -107,10 +100,10 @@ function upload_replace_file_update(&$new_file) {
   //Have to clear the cache because the revision data is cached somewhere
   /*
    * Find the nids where this file is used
-  $query = "SELECT DISTINCT nid FROM {files} WHERE fid=%d";
+  $query = "SELECT DISTINCT id FROM {file_usage} WHERE fid=%d";
   $result = db_query($query, $new_file->fid);
   while($data = db_fetch_object($result)) {
-    cache_clear_all("content:$data->nid");
+    cache_clear_all("node:$data->id");
   }
   */
   //This is inefficent, but how can we determine what nodes use this file?
@@ -118,11 +111,12 @@ function upload_replace_file_update(&$new_file) {
 }
 
 /**
- * HOOK_file_delete, update the filepath in the file object before deleting as we may have altered it above
+ * HOOK_file_delete, update the uri in the file object before deleting as we may have altered it above
  * @param object $new_file
  */
 /*
-function upload_replace_file_delete(&$file) {
-  $file->filepath = db_result(db_query("SELECT filepath FROM {files} WHERE fid = %d", $file->fid));
+function upload_replace_file_delete($file) {
+  $file->uri = db_result(db_query("SELECT uri FROM {file_managed} WHERE fid = %d", $file->fid));
 }
-*/
\ No newline at end of file
+*/
+
