Full state machine implementation