refactored to be more object oriented