Refactoring to use classes