some refactorings to use lambdas