move counter inside loop