Refactor config, command line arguments, and env variables