Split "do things" into "decide what to do" and "do it" parts

Make things easier to test and maintain by splitting the "do the things" code into two phases:

1. Inspect the input and state and decide which operation to perform; and
2. Perform operations.