added necessary checks; added command line argument support