move reponse generating code into prepare_response() method