Refactored code to be object oriented.