Option parsing

Better option parsing, and a bit of clean up elsewhere.