refactored code and taking args from the commandline