loop bug solved