added nfa optimization
added priority to FSM states