updated for nearest neighbors