Can you refactor the lambda to an inner function. It is a bit hard to read.