Refactored code to reflect a more object-oriented approach.