Refactored a lot, tidied code up, added pretty command line diagnostics for myself.