Added command line parsing, and some other cleanup