Fix Bug23: Rewrite the FSM