Refactored code to include classes