Improved automaton logic, removing the merge-joint type.