Refactored code to be more OO