better handling of errors and empty response