     {
         temper[leftidx] = right[gid];
         temper[rightidx] = left[gid];
+        gidout = (gid + blockDim.x) & lastidx;
     }
     else
     {
         gid += blockDim.x;
         temper[leftidx] = right[gid];
         temper[rightidx] = left[gid];
+        gidout = (gid - blockDim.x) & lastidx;
     }
 
     __syncthreads();

    int tid1 = tid + 1;
    int tid2 = ((gid == ht1) ? tid : tid + 2);
    int tid0 = ((gid == height) ? tid+2 : tid);

	// Initialize temper.


	int shft_rd; //Initialize the shift to the read row (opposite of written)
	int leftidx = tid/2 + ((tid/2 & 1) * blockDim.x) + (tid & 1);
	int rightidx = (blockDim.x - 2) + ((tid/2 & 1) * blockDim.x) + (tid & 1) -  tid/2;
    int lastidx = ((blockDim.x*gridDim.x)-1);
    int gidout = (gid + blockDim.x) & lastidx;

    //Assign the initial values to the first row in temper, each warp (in this
	//case each block) has it's own version of temper shared among its threads.
