Fixed kd-tree destroying function