Refactored to use classes for more readability