Refined timeout code