Updated error handling with timeouts.