Convert some code to idiomatic C++11 using range for and nonmember begin/end