fixing bad loop