Revert state machine reimplementation

Rewrote the existing code to remove the 'state machine' abstraction. I'm
still not quite sure of the best way to handle this so I'll leave it as a
branch for now.
Merge branch 'revert-state-machine'

Adopting this change because it seems to be easier to work with. See also
the commit message for the initial branch commit.