Figure 8:
State machine.