Added a weighting function; 5 nearest neighbors found with the weights