Logic cleanup for REPL