Re-write of argument parsing, breaks tests but works better.