refactoring lambda abstraction code