diff --git a/fe_paths/fe_paths.module b/fe_paths/fe_paths.module
index 2ce13c8..ce17330 100644
--- a/fe_paths/fe_paths.module
+++ b/fe_paths/fe_paths.module
@@ -349,7 +349,7 @@ function fe_paths_file_process($file, $entity, $type, $field_name = NULL) {
  */
 function fe_paths_move_file($file, $replace_path, $replace_filename, $token_type, $config_data, $entity = NULL) {
   $scheme = file_uri_scheme($file->uri);
-  $old_dir_uri = str_replace('/' . $file->filename, '', $file->uri);
+  $old_dir_uri = drupal_dirname($file->uri);
 
   $path = token_replace($replace_path, array(
     $token_type => $entity,
@@ -407,17 +407,18 @@ function fe_paths_move_file($file, $replace_path, $replace_filename, $token_type
 
   // Create directory, if necessary.
   file_prepare_directory($directory, FILE_CREATE_DIRECTORY);
-  if (file_move($file, $new_uri)) {
+  if ($file_moved = file_move($file, $new_uri)) {
     // Check, if directory is empty, and delete it, if yes, remove it.
     $files = file_scan_directory($old_dir_uri, '/.*/');
     if (file_exists($old_dir_uri) && empty($files)) {
       drupal_rmdir($old_dir_uri);
     }
-    // Because of file_move works with a cloned $file object, need to update
-    // this $file object.
-    $file->filename = $filename;
-    $file->uri = $new_uri;
-    return $file;
+    // Because file_move returns a clone of $file object, we need to return
+    // the $file_moved object.
+    // file_move() > file_unmanaged_move() > file_unmanaged_copy() >
+    // file_destination() may need to change the filename & uri when duplicates
+    // of that filename exist in the destination.
+    return $file_moved;
   }
   else {
     return FALSE;
@@ -447,8 +448,8 @@ function fe_paths_file_process_available($file) {
     return FALSE;
   }
 
-  if (!array_key_exists($file->origname, $processed)) {
-    $processed[$file->origname] = TRUE;
+  if (!array_key_exists($file->fid, $processed)) {
+    $processed[$file->fid] = TRUE;
   }
   else {
     $return = FALSE;
