Added a check for timeout cancellation