Adding code to correctly handle timeouts