refactor to use more lambdas