fix variable scope issue in REPL