       generateLongsFromGMP(a[j * nr_rows + i], tmpX[j * nr_rows + i], lengthOwnLimbs[j * nr_rows + i], ownLimbSize, maxExp); 
       if (minLengthOwnLimbs > lengthOwnLimbs[j * nr_rows + i]) minLengthOwnLimbs = lengthOwnLimbs[j * nr_rows + i];
     }
-
+  
   
   // Allocate the memory for the set of matrices (make all elements have the same length) such that 
   // elements of the matrices are closer in memory 
   // This might need to be rethough
-  x = (long long **) malloc(minLengthOwnLimbs * sizeof *x + (minLengthOwnLimbs * (nr_rows * nr_cols * sizeof **x)));
+  x = (long long **)malloc(minLengthOwnLimbs * sizeof *x);
+  for(int k = 0; k < sizeOfArray; k++)
+    x[k] = (long long *) malloc(nr_rows * nr_cols * sizeof **x);
   sizeOfArray = minLengthOwnLimbs;
   
   for(int k = 0; k < sizeOfArray; k++)
-    for(int i = 0; i < nr_rows; ++i)
-      for(int j = 0; j < nr_cols; ++j) {
+    for(int i = 0; i < nr_rows; i++)
+      for(int j = 0; j < nr_cols; j++) {
 	x[k][j * nr_rows + i] = tmpX[j * nr_rows + i][k];
       }
   free(tmpX);

       std::cout<< tr << std::endl;
     }
     std::cout << "*****************************" << std::endl;
     
     std::cout << "Binary..." << f.get_str(exp, 2) << std::endl;
     long long toAdd = 12;
     addToGMP(f, toAdd, -7);
     std::cout << "Binary added..." << f.get_str(exp, 2) << std::endl;
     std::bitset<64> tr(toAdd);
     std::cout << "what to add ..." << tr << std::endl; 

     std::cout << "*****************************" << std::endl;
     // Allocate 3 arrays on CPU     
     int nr_rows_A, nr_cols_A, nr_rows_B, nr_cols_B, nr_rows_C, nr_cols_C;
     timeval t1, t2;

     // for simplicity we are going to use square arrays

      int toCmp =  a[j * nr_rows + i].get_mpf_t()->_mp_exp;
      if (toCmp > maxExp) maxExp = toCmp;
    }
  exp = maxExp * INT64L;
  
  
  // Generate the array of 64-bit matrices
  long minLengthOwnLimbs = LLONG_MAX;
