Hm, this seems expensive. I was thinking of using a priority queue that is pulled until the condition is met, but then bookkeeping of attempt counts will not work as it works now.