--- a/src/class_borders.cc
+++ b/src/class_borders.cc
@@ -246,6 +246,8 @@
   //un-normalize the vectors before writing them to a file:
   //(only if -u set)
   if (opt_args.uflag && opt_args.normfile!=NULL) {
+    real_a **bord2;
+    real_a **grad2;
     real_a **mat;
     gsl_matrix *mat2;
     gsl_vector *xy;
@@ -268,12 +270,14 @@
 
     printf("Solving to convert borders data back to un-transformed coordinates...\n");
     if (nvar<nvar1) fprintf(stderr, "class_borders: warning, inverse coord. transformation may be under-determined\n");
-    xy=gsl_vector_alloc(nvar);
-    b=gsl_vector_alloc(nvar1);
+
+    //xy=gsl_vector_alloc(nvar1);
+    //b=gsl_vector_alloc(nvar);
     mat2=gsl_matrix_alloc(nvar1, nvar);
     s=gsl_vector_alloc(nvar);
     vt=gsl_matrix_alloc(nvar, nvar);
     work=gsl_vector_alloc(nvar);
+
     for (dim_ta i=0; i<nvar1; i++) {
       for (dim_ta j=0; j<nvar; j++) {
         gsl_matrix_set(mat2, i, j, mat[i][j]);
@@ -284,30 +288,59 @@
     //that reduce the dimension--if the dimension reduction has been done
     //effectively, the results might even be somewhat sensible
     gsl_linalg_SV_decomp(mat2, vt, s, work);
+    //transpose decomposition:
+
     gsl_vector_free(work);
+    bord2=allocate_matrix<real_a, nel_ta>(opt_args.n, nvar1);
+    grad2=allocate_matrix<real_a, nel_ta>(opt_args.n, nvar1);
     for (nel_ta i=0; i<opt_args.n; i++) {
-      for (dim_ta k=0; k<nvar1; k++) {
+      double tmp_b;
+      double tmp_g;
+      for (dim_ta j=0; j<nvar1; j++) {
+        bord2[i][j]=ave[j];
+        grad2[i][j]=0;
+        for (dim_ta k=0; k<nvar; k++) {
+          double s_k=gsl_vector_get(s, k);
+          if (s_k == 0) continue;
+          tmp_b=0;
+          tmp_g=0;
+          for (dim_ta l=0; l<nvar; l++) {
+            tmp_b+=gsl_matrix_get(vt, l, k)*border[i][l];
+            tmp_g+=gsl_matrix_get(vt, l, k)*gradient[i][l];
+          }
+          bord2[i][j]+=tmp_b*gsl_matrix_get(mat2, j, k)/s_k;
+          grad2[i][j]+=tmp_g*gsl_matrix_get(mat2, j, k)/s_k;
+        }
+      }
+      /*
+      for (dim_ta k=0; k<nvar; k++) {
         gsl_vector_set(b, k, border[i][k]);
       }
       //invert the transformation matrix:
-      gsl_linalg_SV_solve(mat2, vt, s, b, xy);
-      for (dim_ta j=0; j<nvar; j++) {
+      gsl_linalg_SV_solve(vt, mat2, s, b, xy);
+      for (dim_ta j=0; j<nvar1; j++) {
         border[i][j]=gsl_vector_get(xy, j)+ave[j];
       }
-      for (dim_ta k=0; k<nvar1; k++) {
+      for (dim_ta k=0; k<nvar; k++) {
         gsl_vector_set(b, k, gradient[i][k]);
       }
-      gsl_linalg_SV_solve(mat2, vt, s, b, xy);
-      for (dim_ta j=0; j<nvar; j++) {
+      gsl_linalg_SV_solve(vt, mat2, s, b, xy);
+      for (dim_ta j=0; j<nvar1; j++) {
         gradient[i][j]=gsl_vector_get(xy, j);
       }
+      */
     }
     nvar=nvar1;
+    delete_matrix(border);
+    delete_matrix(gradient);
+
+    border=bord2;
+    gradient=grad2;
 
     delete_matrix(mat);
     gsl_matrix_free(mat2);
-    gsl_vector_free(xy);
-    gsl_vector_free(b);
+    //gsl_vector_free(xy);
+    //gsl_vector_free(b);
     gsl_vector_free(s);
     gsl_matrix_free(vt);
   }