some nfa and refactoring