todo
Refactor main
Use an enum for ExitCode.
Clean termination rather than aborting after uncaught problems.