Work in progress: clean up error handling in preparation for REPL mode.