                   (message "Refactoring failed: %s" rsn))
                  (['rex ['error rsn]]
                   (message "Refactoring failed: %s" rsn))
-                 (['rex pid]
-                  (apply-refac-cmds current-file-name pid 'none)
+                 (['rex ['ok pid]]
+                  (apply-refac-cmds current-file-name (list 'ok nil))
                   )))))
-      (message "Refactoring aborted.")))) 
-
-(defun apply-refac-cmds(current-file-name pid previous_result)
+      (message "Refactoring aborted."))))
+
+(defun apply-refac-cmds(current-file-name previous_result)
   "apply a sequence of refactoring commands."
-  (message "pid: %s" pid) 
   (erl-spawn
-    (erl-send-rpc wrangler-erl-node 'gen_composite_refac 'get_next_command (list pid previous_result))
-    (erl-receive (current-file-name pid)
+    (erl-send-rpc wrangler-erl-node 'gen_composite_refac 'get_next_command (list previous_result))
+    (erl-receive (current-file-name)
         ((['rex ['badrpc rsn]]
           (message "Refactoring failed: %s" rsn))
          (['rex ['error rsn]]
           (message "Refactoring failed: %s" rsn)) 
-         (['rex ['ok 'none modified ['atomic_cr_failed rsn]]]
-                (message "Composite refactoring failed: %s" rsn)) 
-         (['rex ['ok 'none modified msg]] 
+         (['rex ['ok 'none modified ['error rsn]]]
           (progn
-            (if (eq modified nil)
-                (message "Refactoring finished, and no file has been changed.")
-              (update-buffers modified)
-              (preview-commit-cancel current-file-name modified nil)
-              (with-current-buffer (get-file-buffer-1 current-file-name)
-                nil))))
-         (['rex ['ok ['refactoring cmd] next_pid]]
-          (apply-a-refac-cmd current-file-name next_pid cmd)) 
-         (['rex ['ok ['question msg cmd] next_pid]]
+            (update-buffers modified)
+            (message "Composite refactoring failed: %s" rsn)))
+          (['rex ['ok 'none modified msg]] 
+           (progn
+             (if (eq modified nil)
+                 (message "Refactoring finished, and no file has been changed.")
+               (update-buffers modified)
+               (preview-commit-cancel current-file-name modified nil)
+               (with-current-buffer (get-file-buffer-1 current-file-name)
+                 nil)
+               (message "Refactoring finished."))))
+         (['rex ['ok ['refactoring cmd]]]
+          (apply-a-refac-cmd current-file-name cmd)) 
+         (['rex ['ok ['interactive msg cmd]]]
           (if (y-or-n-p msg)
-              (apply-a-refac-cmd current-file-name next_pid cmd)
-            (apply-refac-cmds current-file-name next_pid 'none)))
-         (['rex ['ok ['repeat_question msg cmd] next_pid]]
-          (message "next_pid %s" next_pid)
+              (apply-a-refac-cmd current-file-name cmd)
+            (apply-refac-cmds current-file-name (list 'ok nil))))
+         (['rex ['ok ['repeat_interactive msg cmd]]]
           (if (y-or-n-p msg)
-              (apply-a-refac-cmd current-file-name next_pid cmd)
-            (apply-refac-cmds current-file-name next_pid 'none)))
+              (apply-a-refac-cmd current-file-name cmd) 
+            (apply-refac-cmds current-file-name 'none)))
          (['rex result]
-          (message "Result: %s" result))
-          ))))
+          (message "Unexpected result: %s" result))
+         ))))
  
  
-(defun apply-a-refac-cmd(current-file-name pid cmd)  
+(defun apply-a-refac-cmd(current-file-name cmd)   
   "apply a sub refayctoring of a composite refactorings."
   (interactive) 
   (setq mod_name (elt cmd 0)) 
-  (setq refac_name (elt cmd 1)) 
+  (setq refac_name (elt cmd 1))  
   (setq args (elt cmd 2))
   (highlight_sels args)
   (setq newargs (get_user_inputs args))
-  (message "newargs: %s" newargs)
   (org-delete-overlay highlight-region-overlay)
   (erl-spawn 
     (erl-send-rpc wrangler-erl-node 'wrangler_refacs 'try_refactoring (list mod_name refac_name (append newargs (list tab-width))))
-    (erl-receive(current-file-name pid)
+    (erl-receive(current-file-name)
         ((['rex ['badrpc rsn]]
           (progn 
             (message "Refactoring failed: %S" rsn)
-            (apply-refac-cmds current-file-name pid (list 'error rsn))))
+            (apply-refac-cmds current-file-name (list 'error rsn))))
          (['rex ['error rsn]]
            (progn
              (message "Refactoring failed: %s" rsn)
-             (apply-refac-cmds current-file-name pid (list 'error rsn))))
+             (apply-refac-cmds current-file-name (list 'error rsn))))
          (['rex [['ok modified] name_change]]
           (progn
             (message "Refactoring succeeded %s" modified)
             (update-buffers modified)
-            (apply-refac-cmds current-file-name pid (list (list 'ok modified) name_change))))
+            (apply-refac-cmds current-file-name (list (list 'ok modified) name_change))))
          (['rex ['ok modified]]
           (progn
             (message "Refactoring succeeded %s" modified)
             (update-buffers modified)
-            (apply-refac-cmds current-file-name pid (list (list 'ok modified) nil))))
+            (apply-refac-cmds current-file-name (list 'ok modified))))
          (['rex ['ok modified warning-msg]]
           (progn
             (message "Refactoring succeeded %s" modified)
             (update-buffers modified)
-            (apply-refac-cmds current-file-name pid (list 'ok modified))))
+            (apply-refac-cmds current-file-name (list 'ok modified))))
          (['rex result]
-          (message "Result: %s" result))
+          (message "Unexpected result: %s" result))
          )))) 
           
 (defun update-buffers(files)

  (dolist (uf unopened-files)
    (kill-buffer (get-file-buffer-1 uf)))
  (setq unopened-files nil)
  candidates-not-to-change)
 

(defun apply-composite-refac(callback-module-name) 
  "Apply a composite refactoring defined by behaviour gen_composite_refac"
  (interactive (list (read-string "Refactoring Callback module name: ")))
  (setq composite_refac 'true)
  (let* ((buffer (current-buffer))
        (current-file-name (buffer-file-name))
        (line-no (current-line-no))

(setq ediff-ignore-similar-regions t)
(setq refactor-mode nil)
(setq has-warning 'false)

(defun wrangler-ediff(file1 file2)
  "run ediff on file1 ans file2"
