New KNN code -should compile now

Second trial, hope it passes all the compilation tests now.