reformat the traversal function