Re-organized response generation code.