refactor response handler