fixed a loop bug