refactor to support command line