Refactored code and placed into modules