Changed iterators to use auto, many of which using range-based loops

This honestly seems way more complex than what we already have, and I personally don't think it would improve readability in the function.