Refactored handler