Refactor command line scripts