Split up the big REPL function.