refactor logic for generating command line arguments