More refactoring on the traversal code.