Fsm Optimization