sort out duplications ie cope with self edges