reorganize REPL js code (partial commit)