refactored to not use multiple classes as specified in assignment