refactored with classes