Transformation from leaves to trees