use a more robust method for stopping traversal