fixed bug that reset iterator too soon