 (defun abort-changes()
   "abort the refactoring results"
   (erl-spawn
-    (erl-send-rpc wrangler-erl-node 'wrangler_preview_server 'abort (list composite_refac))
+    (erl-send-rpc wrangler-erl-node 'wrangler_preview_server 'abort (list))
     (erl-receive ()
 	((['rex ['badrpc rsn]]
 	  (setq refactor-mode nil)

                  (message "Refactoring failed: %s" rsn))
                 (['rex ['error rsn]]
                  (message "Refactoring failed: %s" rsn))
                 (['rex pid]
                  (apply-refac-cmds current-file-name pid 'none)
                  )))))
      (message "Refactoring aborted.")))) 

(defun apply-refac-cmds(current-file-name pid 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)
        ((['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]] 
          (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]]
          (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)
          (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 result]
          (message "Result: %s" result))
          ))))
 
 
(defun apply-a-refac-cmd(current-file-name pid cmd)  
  "apply a sub refayctoring of a composite refactorings."
  (interactive) 
  (setq mod_name (elt cmd 0)) 
  (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)
        ((['rex ['badrpc rsn]]
          (progn 
            (message "Refactoring failed: %S" rsn)
            (apply-refac-cmds current-file-name pid (list 'error rsn))))
         (['rex ['error rsn]]
           (progn
             (message "Refactoring failed: %s" rsn)
             (apply-refac-cmds current-file-name pid (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))))
         (['rex ['ok modified]]
          (progn
            (message "Refactoring succeeded %s" modified)
            (update-buffers modified)
            (apply-refac-cmds current-file-name pid (list (list 'ok modified) nil))))
         (['rex ['ok modified warning-msg]]
          (progn
            (message "Refactoring succeeded %s" modified)
            (update-buffers modified)
            (apply-refac-cmds current-file-name pid (list 'ok modified))))
         (['rex result]
          (message "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: ")))
  (let* ((buffer (current-buffer))
        (current-file-name (buffer-file-name))
        (line-no (current-line-no))
