update tree traversing algorithm