Perform breadth-first traversal in collect_things_recur.

This should make results more accurate when the traversal limit is reached.
Also use a mapping to track visited things, to improve performance.