Use recur to avoid stack overflow when removing a large number of items.