optimize rebuild binary tree