fix bugs in setting of nnz attribute
refactor expansion loop to remove serial dependence