The problem is caused by using tremove near the start of a very large table, a large number of times.
On a very large auctionhouse, Stage 4 can take 5-10 minutes.
From a test with the code altered to copy the entries we want to keep into a new table, Stage 4 on the same auctionhouse took 1-2 seconds.
(i.e. tinsert to the end of a table is much much faster than tremove from the start)
However we do not want to copy the whole table if the number of deletions is small - and particularly not if there are no deletions!
We don't know the actual number of deletions until we have run Stage 4's tests.
We can roughly estimate the number of deletions.
Alternatively we can make two passes for Stage 4: one to count and flag entries to be deleted and a second to do the actual deletions.