refactored (simplified)