revisions based on code for fptree_query