bug fix when passing in tree to be written