Added Automata object and moved debug code to it. Mostly works.