Functional state machine