Various fixes to use more C++11 features

As we already use C++11 lambdas, we should also use foreach and std::string.
personally I'd not focus on ideology: initially I wrote C program and modified it to be C++ just to make parts nicer. There is no issues in this code :)