Converting code to use C++(11) idioms instead of C

As we already use C++11 lambdas, we should also use foreach and std::string.