refactored to be object oriented