Added some command line options and some code cleanup