Replace all for loops with more ruby-like iterators.