Internal refactor to master cmd

First-pass breakup of logical components into function calls for general
maintainability, refactorability, merge-conflict-avoidance, etc.
We shouldn't be taking env vars here really.  These should come off config, and if we want to bind env to config we do that outside of these.