Changed count_leaves and minimal_element to be implementation agnostic