Some refactoring and making KdTree Foldable
Massive refactor to go from KdSpace to just a pair of functions.