refactored code to use object-oriented methods