Algorithm updated to NW-NFA with ternary trie encoding. DFA bugs fixed.