implement tree funct