modified to use lambdas