Implemented FSM as template.