Refactored based on feedback