Refactored code to create a module