Updated loop to new C++11 foreach notation.