changes for correct loop generation