Refactored response logic