fixed infinite loop during Prims