setting the stack to empty will cause the traversal to terminate
setstack(ps);