refactored eof-driven REPL