refactored for object-oriented purposes