Added threading and error handling around timeouts