accept various command line arguments; code refactoring