fixed for changes in K_image, K syntax; replaced kdtree with search for issues with crashing implementation of kdtree