refactor to use lambdas