Simplified and refactored