a slightly cleaner rewrite of option parser