fix internal loop counter