Cleanup: significantly simplify REPL code