finalized state machine implementation