Used C++11's ranged-based for loops where applicable