Refactor logic so that every branch of the big if-else looks the same.
Refactored ugly case statement into a map and loop.  Is it easier to understand?