Fixes a bug in the nearest neighbors algorithm