Fix topology building if paths are taken twice (fixes #722)