Test for end of oid tree without breaking collection loop.

This fixes #368