Changed design pattern of code
Refactored code to closure form
Formatted