Refactor response generation.