Refactored code to modules