simplify traversal function