correctify the traversal order