maintain traversal stack properly