tree example with working counting function