Refactored a few for loops to use C++11 style for loops