Refactoring code with lambda expressions