Fix bug in merge_states

Cases in which the s and r states shared a transition and the s
state looped back to itself on that transition completely ingored
the transition on the r state rather than merging the two.