refactored using objects