fixed tree writing bug