Refactor the communication with repl instance