Starting attept at iterative historgram and freeing the tree.