added a filter method in tree traversal