version_1.4 full implemtation of tree algorithm