refactoring automaton factory