Improved FSM template.