Move core command-processing logic out to `process_action` from `main`, in preparation for the introduction of REPL code.
Fix obvious errors caused by me forgetting which language I was writing.