fix issue with looping counter