fix traversal logic