Cleaning up parsing of arguments, and adding better error handling