Adds recursive tree counter

- Recursive tree counter added. This was simpler to build as two
separate functions with one calling itself.