DFA example. a bit verbose, but working for now.