loop bug fixed