generalized traversal code