added nearest neighbor support