Refactoring redundant functiond with anonymous apply