Rewrite timeouts to use a priority queue