Run uniq and merge before constructing topology.