Vastly improved argument parsing and general code cleanup