basic optimization of nfa