One thing you could do is add an internal `setState(newState)` function, which makes sure that the new state is the next logical step in the process.