Refactored code to make it abide by OOP