response handler and errors refactored