Modified functions and changed to accept command line arguments.