Internal refactor to master cmd

First-pass breakup of logical components into function calls for general
maintainability, refactorability, merge-conflict-avoidance, etc.
Agree, but in the next refactor. This is just equivalent to the current hacky env config stuff.