Finite State Machine Implementation