Enhanced to use timeout rather than tick threshold.