Simplified DFA and cleaned up code.