refactored code to be more OO