fix a bug in BalanceTreeNode function