Replaced some code with lambdas