Sync tree.go with upstream