ensure correct loop end