cleanup and fixes to error handling in http client