fixed loop bug