Fix state merge issue

Previously, a state with unknown transitions would be merged
with any other state. Add new, stricter conditions so that two
states will only be merged if they have a matching known
transition.