Refactored building of nfa