write output function
update code through tree level and group