Modify create_nearest_neighbor to return shared_ptr