Better state machine