Cleaned up the code a bit and added command line parameters