Some cleanup and use of range-based loops