Improve error handling and timeouts