Conversion to state machine