finished automaton implementation