Refactored code to follow OOP design principles