fixing the loop counter var