Fixed counter variable issue