Refactored response handling