constructing final output tree done