Replaced C++11 lambda functions with messy explicit closures.