fixed a bunch of broken functions
pre-kdtree re-implementation