Miscelaneous fixes in kdtree templates