Annotation: the proposed algorithm assumes that root itself is accepted by the filter (so not skipped/rejected). But then in the rest of the code the same assumption is made, so should not be a big problem now. Then you tend to rewrite things in each iteration some more, so looking forward what you come up with :)