Improved Finite State Machine