fixed traversal logic