Far cleaner, and more correct to run the traversal twice. Fixes a case where we propagate depth state through multiple functions.