Fixed memory corruption in KD-tree.