Adding FSM to control flow