 		     nil))))
 	       (message "Refactoring succeeded!")))))))
 
-(defun create-new-file-p (name)
-  (let  ((filename (expand-file-name (concat name ".erl") (file-name-directory (buffer-file-name)))))
-         (if (file-exists-p filename) t
-	     (yes-or-no-p "The specified module does not exist, do you want to create one? "))))
+(defun create-new-file-p (filename erlang-refac-search-paths)
+  (if (equal (locate-file (concat filename ".erl") erlang-refac-search-paths) nil)
+      (yes-or-no-p "The specified module does not exist, do you want to create one?")
+    t))
 
  
 ;; redefined get-file-buffer to handle the difference between

	       (message "Refactoring succeeded!")))))))


(defun erl-refactor-rename-mod (node name)
  "Rename the current module name."
  (interactive (list (erl-target-node)

	(line-no           (current-line-no))
        (column-no         (current-column-no))
	(buffer (current-buffer))
        (create-new-file   (create-new-file-p name erlang-refac-search-paths)))
    (erl-spawn
      (erl-send-rpc node 'wrangler_distel 'move_fun
		    (list current-file-name line-no column-no name create-new-file erlang-refac-search-paths))
