Improve option parsing and error checking