improve error and timeout handling