Refactoring massive if-then loop to dispatch to a set of private methods instead of using open coding.