Added better check for task timeout