added functions for subtree counting