Refactored code to closure form