rebalancing kd tree