This codes used to update the trees