Use C++11 range-for and references for better performance