Make pack object lookup use loops

We currently have three-function cycle which keeps calling each other until we find a base. This is not ideal, as it means that we have unbounded stack growth.

Instead, let's use a couple of loops. One to find out what objects we need and another to apply the deltas. This also makes it IMO somewhat more readable.