rewrite kd-tree search by template