Refactoring the command line bits to use branching using a map to simplify command validation and break out the command implementations into their own functions.