This version the fsm is written