improve tree algorithms