Refactored for performance