refactored DFA code