added C++11 and used lambdas