diff --git a/src/spm_gather.c b/src/spm_gather.c
index 82cdce679c6808cf692b1f74b81f627f2e19a9ed..93bd05b7fbd7ffe0f3f7ca5bceea17b6c3dfbbd9 100644
--- a/src/spm_gather.c
+++ b/src/spm_gather.c
@@ -115,7 +115,7 @@ spm_gather_csx_update( const spmatrix_t *spm,
     for ( c=1; c<spm->clustnbr; c++ ) {
         /* Let's start shifting the value after the first array */
         spm_int_t shift = recvdispls[c];
-        spm_int_t end   = ( c < (spm->clustnbr-1) ) ? recvdispls[c+1] : spm->gN+1;
+        spm_int_t end   = ( c < (spm->clustnbr-1) ) ? recvdispls[c+1] : spm->gN;
         spm_int_t i;
 
         to_add += recvcounts[c-1];
@@ -123,6 +123,9 @@ spm_gather_csx_update( const spmatrix_t *spm,
             colptr[i] += to_add;
         }
     }
+    assert( to_add + recvcounts[spm->clustnbr-1] == spm->gnnz );
+    /* Set the last value */
+    colptr[spm->gN] = colptr[0] + spm->gnnz;
 }
 
 /**
@@ -177,7 +180,6 @@ spm_gather_csx_continuous( const spmatrix_t *oldspm,
                 recvdispls[c] = recvdispls[c-1] + recvcounts[c-1];
                 recvcounts[c] = allcounts[ 3 * c ];
             }
-            recvcounts[ oldspm->clustnbr - 1 ] += 1; /* Add the extra elements */
 
             /* Initialize the new pointers */
             assert( newspm );
@@ -186,11 +188,6 @@ spm_gather_csx_continuous( const spmatrix_t *oldspm,
             newval =  newspm->values;
         }
 
-        /* Add the first value from the first node */
-        if ( oldspm->clustnum == oldspm->clustnbr-1 ) {
-            n++;
-        }
-
         /* Gather the colptr */
         if ( root == -1 ) {
             MPI_Allgatherv( oldcol, n, SPM_MPI_INT,
diff --git a/src/z_spm_expand.c b/src/z_spm_expand.c
index ad757e3f142d24264f99038d5c864f67077ceac9..07a38e8ce4def2c48d8a7e2ee8f69f365f4cf27e 100644
--- a/src/z_spm_expand.c
+++ b/src/z_spm_expand.c
@@ -117,9 +117,9 @@ z_spmCSCExpand( const spmatrix_t *spm_in, spmatrix_t *spm_out )
 
         /* Sum the heights of the elements in the column */
         newcol[1] = newcol[0];
-        for(k=oldcol[0]; k<oldcol[1]; k++)
+        for(k=oldcol[0]; k<oldcol[1]; k++, oldrow++ )
         {
-            ig   = oldrow[k-baseval] - baseval;
+            ig   = *oldrow - baseval;
             dofi = (spm_in->dof > 0 ) ? spm_in->dof : dofs[ig+1] - dofs[ig];
             newcol[1] += dofi;
 
@@ -280,9 +280,9 @@ z_spmCSRExpand( const spmatrix_t *spm_in, spmatrix_t *spm_out )
 
         /* Sum the width of the elements in the row */
         newrow[1] = newrow[0];
-        for(k=oldrow[0]; k<oldrow[1]; k++)
+        for(k=oldrow[0]; k<oldrow[1]; k++, oldcol++)
         {
-            jg   = oldcol[k-baseval] - baseval;
+            jg   = *oldcol - baseval;
             dofj = (spm_in->dof > 0 ) ? spm_in->dof : dofs[jg+1] - dofs[jg];
             newrow[1] += dofj;