refactored to use classes