Use a state machine