Removed unnecessary loop over undirectedIds