Factor out mergeTransitions