Porting nii processing functions from metaaccumulate