refactor the response handler