Main: refactor repl actions to remove some code duplication