add kd tree code