Replace counters with range-do loops

Optimize and tidy