stack automaton fix/refactor