Fix CLI bugs, exit code and exceptions

Addresses two bugs in #908