added nearest neighbor code