added a function to count the number of nodes in the tree