Updated Nearest Neighbor code