Improved subtree counter