Added better command line option parsing and optional output file.