added better exception handling and fixed command line parameters