fixed bugs in deleteLoops()