first impl using nearest neighbor