Refactoring some loops to fast enumeration.