diff --git a/groupttest.cc b/groupttest.cc
index ddb69e17070b546eda80f6aee89698e291dfdbaa..1f098e117665d91da1e2e7aaaaa364ffffab1b17 100644
--- a/groupttest.cc
+++ b/groupttest.cc
@@ -214,6 +214,7 @@ double pvalue(double tX, double dof) {
 } 
 
 
+
 vector<int> get_sortindex(const Matrix& vals)
 {
   // return the mapping of old indices to new indices in the
@@ -226,12 +227,11 @@ vector<int> get_sortindex(const Matrix& vals)
   sort(sortlist.begin(),sortlist.end());  // O(N.log(N))
   vector<int> idx(length);
   for (int n=0; n<length; n++) {
-    idx[n] = sortlist[n].second;
+    idx[sortlist[n].second-1] = n+1;
   }
   return idx;
 }
 
-
 ////////////////////////////////////////////////////////////////////////////
 
 // Main function - this does all the work