make use of Statement::apply()

Refactoring to simplify code using C++ lambdas and apply().