Refactored for maintainability