Fixed some kdtree traversal logic.