State machine infrastructure