refactor on automaton