implementing output tree