update tree sort code