Index: kernel/tgb.cc
===================================================================
--- kernel/tgb.cc	(revision a64791477ec20b2ed1ff3c7042d7f2dc9c892600)
+++ kernel/tgb.cc	(revision 2fc9743b1a7666eb52024c75c84573590d6aaaaa)
@@ -11,5 +11,4 @@
 //#include <vector>
 //using namespace std;
-
 
 ///@TODO: delay nur auf Sugarvergr?erung
@@ -69,10 +68,13 @@
   }
 }
-static BOOLEAN monomial_root(poly m, ring r){
+static BOOLEAN monomial_root(poly m, ring r)
+{
     BOOLEAN changed=FALSE;
     int i;
-    for(i=1;i<=rVar(r);i++){
+    for(i=1;i<=rVar(r);i++)
+    {
         int e=p_GetExp(m,i,r);
-        if (e>1){
+        if (e>1)
+	{
             p_SetExp(m,i,1,r);
             changed=TRUE;
@@ -84,5 +86,6 @@
     return changed;
 }
-static BOOLEAN polynomial_root(poly h, ring r){
+static BOOLEAN polynomial_root(poly h, ring r)
+{
   poly got=gcd_of_terms(h,r);
   BOOLEAN changed=FALSE;
@@ -95,5 +98,6 @@
          poly div_by=pDivide(copy, got);
          poly iter=h;
-         while(iter){
+         while(iter)
+	 {
             pExpVectorSub(iter,div_by);
             pIter(iter);
@@ -127,6 +131,4 @@
 //die meisten Varianten stossen sich an coef_buckets
 
-
-
 #ifdef LEN_VAR1
 // erste Variante: Laenge: Anzahl der Monome
@@ -156,12 +158,8 @@
 #endif
 
-
-
-
-
-
-int QlogSize(number n){
-
-    if (SR_HDL(n) & SR_INT){
+int QlogSize(number n)
+{
+    if (SR_HDL(n) & SR_INT)
+    {
        long i=SR_TO_INT(n);
        if (i==0) return 0;
@@ -181,5 +179,4 @@
 }
 
-
 #ifdef LEN_VAR3
 static inline wlen_type pSLength(poly p,int l)
@@ -187,5 +184,6 @@
   wlen_type c;
   number coef=pGetCoeff(p);
-  if (rField_is_Q(currRing)){
+  if (rField_is_Q(currRing))
+  {
     c=QlogSize(coef);
   }
@@ -194,5 +192,6 @@
   if (!(TEST_V_COEFSTRAT))
       return (wlen_type)c*(wlen_type)l /*pLength(p)*/;
-  else {
+  else
+  {
     wlen_type res=l;
     res*=c;
@@ -213,5 +212,6 @@
     coef=pGetCoeff(lm);
     //c=nSize(pGetCoeff(lm));
-  if (rField_is_Q(currRing)){
+  if (rField_is_Q(currRing))
+  {
     c=QlogSize(coef);
   }
@@ -227,18 +227,23 @@
   #ifdef HAVE_COEF_BUCKETS
   assume(b->buckets[0]==kBucketGetLm(b));
-  if (b->coef[0]!=NULL){
-
-    if (rField_is_Q(currRing)){
+  if (b->coef[0]!=NULL)
+  {
+    if (rField_is_Q(currRing))
+    {
       int modifier=QlogSize(pGetCoeff(b->coef[0]));
       c+=modifier;
-  }
-    else{
+    }
+    else
+    {
       int modifier=nSize(pGetCoeff(b->coef[0]));
-      c*=modifier;}
-    }
+      c*=modifier;
+    }
+  }
   #endif
-  if (!(TEST_V_COEFSTRAT)){
-  return s*c;
-  } else
+  if (!(TEST_V_COEFSTRAT))
+  {
+    return s*c;
+  }
+  else
   {
     wlen_type res=s;
@@ -254,5 +259,6 @@
   int c;
   number coef=pGetCoeff(p);
-  if (rField_is_Q(currRing)){
+  if (rField_is_Q(currRing))
+  {
     c=QlogSize(coef);
   }
@@ -278,5 +284,6 @@
     coef=pGetCoeff(lm);
     //c=nSize(pGetCoeff(lm));
-  if (rField_is_Q(currRing)){
+  if (rField_is_Q(currRing))
+  {
     c=QlogSize(coef);
   }
@@ -292,11 +299,13 @@
   #ifdef HAVE_COEF_BUCKETS
   assume(b->buckets[0]==kBucketGetLm(b));
-  if (b->coef[0]!=NULL){
-
-    if (rField_is_Q(currRing)){
+  if (b->coef[0]!=NULL)
+  {
+    if (rField_is_Q(currRing))
+    {
       int modifier=QlogSize(pGetCoeff(b->coef[0]));
       c+=modifier;
-  }
-    else{
+    }
+    else
+    {
       int modifier=nSize(pGetCoeff(b->coef[0]));
       c*=modifier;}
@@ -334,11 +343,15 @@
 #endif
 //BUG/TODO this stuff will fail on internal Schreyer orderings
-static BOOLEAN elength_is_normal_length(poly p, slimgb_alg* c){
+static BOOLEAN elength_is_normal_length(poly p, slimgb_alg* c)
+{
     ring r=c->r;
     if (p_GetComp(p,r)!=0) return FALSE;
-    if (c->lastDpBlockStart<=pVariables){
+    if (c->lastDpBlockStart<=pVariables)
+    {
         int i;
-        for(i=1;i<c->lastDpBlockStart;i++){
-            if (p_GetExp(p,i,r)!=0){
+        for(i=1;i<c->lastDpBlockStart;i++)
+	{
+            if (p_GetExp(p,i,r)!=0)
+	    {
                 break;
             }
@@ -350,15 +363,20 @@
         }
         else return FALSE;
-    }else
+    }
+    else
     return FALSE;
 }
 
-static BOOLEAN lies_in_last_dp_block(poly p, slimgb_alg* c){
+static BOOLEAN lies_in_last_dp_block(poly p, slimgb_alg* c)
+{
     ring r=c->r;
     if (p_GetComp(p,r)!=0) return FALSE;
-    if (c->lastDpBlockStart<=pVariables){
+    if (c->lastDpBlockStart<=pVariables)
+    {
         int i;
-        for(i=1;i<c->lastDpBlockStart;i++){
-            if (p_GetExp(p,i,r)!=0){
+        for(i=1;i<c->lastDpBlockStart;i++)
+	{
+            if (p_GetExp(p,i,r)!=0)
+	    {
                 break;
             }
@@ -370,29 +388,33 @@
         }
         else return FALSE;
-    }else
+    }
+    else
     return FALSE;
 }
 
-static int get_last_dp_block_start(ring r){
+static int get_last_dp_block_start(ring r)
+{
     //ring r=c->r;
     int last_block;
 
-    if (rRing_has_CompLastBlock(r)){
+    if (rRing_has_CompLastBlock(r))
+    {
         last_block=rBlocks(r) - 3;
     }
-    else {last_block=rBlocks(r)-2;}
+    else
+    {last_block=rBlocks(r)-2;}
     assume(last_block>=0);
     if (r->order[last_block]==ringorder_dp)
         return r->block0[last_block];
     return pVariables+1;
-
-}
-
-static wlen_type do_pELength(poly p, slimgb_alg* c, int dlm=-1){
-
+}
+
+static wlen_type do_pELength(poly p, slimgb_alg* c, int dlm=-1)
+{
   if(p==NULL) return 0;
   wlen_type s=0;
   poly pi=p;
-  if(dlm<0){
+  if(dlm<0)
+  {
     dlm=c->pTotaldegree(p);
     s=1;
@@ -400,5 +422,6 @@
   }
 
-  while(pi){
+  while(pi)
+  {
     int d=c->pTotaldegree(pi);
     if(d>dlm)
@@ -411,15 +434,16 @@
 }
 
-wlen_type pELength(poly p, slimgb_alg* c, ring r){
+wlen_type pELength(poly p, slimgb_alg* c, ring r)
+{
   if(p==NULL) return 0;
   wlen_type s=0;
   poly pi=p;
   int dlm;
-    dlm=c->pTotaldegree(p);
-    s=1;
-    pi=p->next;
-
-
-  while(pi){
+  dlm=c->pTotaldegree(p);
+  s=1;
+  pi=p->next;
+
+  while(pi)
+  {
     int d=c->pTotaldegree(pi);
     if(d>dlm)
@@ -435,9 +459,11 @@
 {
   wlen_type s=0;
-  if(lm==NULL){
+  if(lm==NULL)
+  {
     lm=kBucketGetLm(b);
   }
   if(lm==NULL) return 0;
-  if(elength_is_normal_length(lm,ca)) {
+  if(elength_is_normal_length(lm,ca))
+  {
     return bucket_guess(b);
   }
@@ -449,5 +475,4 @@
   #else
 
-
   //int d=pTotaldegree(lm,ca->r);
   int i;
@@ -456,7 +481,9 @@
     if(b->buckets[i]==NULL) continue;
 
-    if ((ca->pTotaldegree(b->buckets[i])<=d) &&(elength_is_normal_length(b->buckets[i],ca))){
+    if ((ca->pTotaldegree(b->buckets[i])<=d) &&(elength_is_normal_length(b->buckets[i],ca)))
+    {
         s+=b->buckets_length[i];
-    } else
+    }
+    else
     {
     s+=do_pELength(b->buckets[i],ca,d);
@@ -467,5 +494,6 @@
 }
 
-static inline int pELength(poly p, slimgb_alg* c,int l){
+static inline int pELength(poly p, slimgb_alg* c,int l)
+{
   if (p==NULL) return 0;
   if ((l>0) &&(elength_is_normal_length(p,c)))
@@ -474,16 +502,15 @@
 }
 
-
-
-
-static inline wlen_type pQuality(poly p, slimgb_alg* c, int l=-1){
-
+static inline wlen_type pQuality(poly p, slimgb_alg* c, int l=-1)
+{
   if(l<0)
     l=pLength(p);
   if(c->isDifficultField) {
-    if(c->eliminationProblem){
+    if(c->eliminationProblem)
+    {
       wlen_type cs;
       number coef=pGetCoeff(p);
-      if (rField_is_Q(currRing)){
+      if (rField_is_Q(currRing))
+      {
          cs=QlogSize(coef);
       }
@@ -508,7 +535,9 @@
 }
 
-static inline int pTotaldegree_full(poly p){
+static inline int pTotaldegree_full(poly p)
+{
   int r=0;
-  while(p){
+  while(p)
+  {
     int d=pTotaldegree(p);
     r=si_max(r,d);
@@ -518,11 +547,14 @@
 }
 
-wlen_type red_object::guess_quality(slimgb_alg* c){
+wlen_type red_object::guess_quality(slimgb_alg* c)
+{
     //works at the moment only for lenvar 1, because in different
     //case, you have to look on coefs
     wlen_type s=0;
-    if (c->isDifficultField){
+    if (c->isDifficultField)
+    {
       //s=kSBucketLength(bucket,this->p);
-      if(c->eliminationProblem){
+      if(c->eliminationProblem)
+      {
     wlen_type cs;
     number coef;
@@ -532,5 +564,6 @@
 
     //c=nSize(pGetCoeff(lm));
-    if (rField_is_Q(currRing)){
+    if (rField_is_Q(currRing))
+    {
       cs=QlogSize(coef);
     }
@@ -538,10 +571,13 @@
       cs=nSize(coef);
     #ifdef HAVE_COEF_BUCKETS
-    if (bucket->coef[0]!=NULL){
-      if (rField_is_Q(currRing)){
+    if (bucket->coef[0]!=NULL)
+    {
+      if (rField_is_Q(currRing))
+      {
         int modifier=QlogSize(pGetCoeff(bucket->coef[0]));
         cs+=modifier;
       }
-      else{
+      else
+      {
         int modifier=nSize(pGetCoeff(bucket->coef[0]));
         cs*=modifier;}
@@ -566,11 +602,9 @@
       else s=bucket_guess(bucket);
     }
-
     return s;
 }
 
-
-
-static void finalize_reduction_step(reduction_step* r){
+static void finalize_reduction_step(reduction_step* r)
+{
   delete r;
 }
@@ -583,26 +617,26 @@
 static int red_object_better_gen(const void* ap, const void* bp)
 {
-
-
   return(pLmCmp(((red_object*) ap)->p,((red_object*) bp)->p));
 }
 
-
-static int pLmCmp_func_inverted(const void* ap1, const void* ap2){
-    poly p1,p2;
+static int pLmCmp_func_inverted(const void* ap1, const void* ap2)
+{
+  poly p1,p2;
   p1=*((poly*) ap1);
   p2=*((poly*)ap2);
-
   return -pLmCmp(p1,p2);
 }
 
-int tgb_pair_better_gen2(const void* ap,const void* bp){
+int tgb_pair_better_gen2(const void* ap,const void* bp)
+{
   return(-tgb_pair_better_gen(ap,bp));
 }
-int kFindDivisibleByInS_easy(kStrategy strat,const red_object & obj){
+int kFindDivisibleByInS_easy(kStrategy strat,const red_object & obj)
+{
   int i;
   long not_sev=~obj.sev;
   poly p=obj.p;
-  for(i=0;i<=strat->sl;i++){
+  for(i=0;i<=strat->sl;i++)
+  {
     if (pLmShortDivisibleBy(strat->S[i],strat->sevS[i],p,not_sev))
       return i;
@@ -610,8 +644,10 @@
   return -1;
 }
-int kFindDivisibleByInS_easy(kStrategy strat,poly p, long sev){
+int kFindDivisibleByInS_easy(kStrategy strat,poly p, long sev)
+{
   int i;
   long not_sev=~sev;
-  for(i=0;i<=strat->sl;i++){
+  for(i=0;i<=strat->sl;i++)
+  {
     if (pLmShortDivisibleBy(strat->S[i],strat->sevS[i],p,not_sev))
       return i;
@@ -646,5 +682,6 @@
 }
 
-static BOOLEAN  ascending(int* i,int top){
+static BOOLEAN  ascending(int* i,int top)
+{
   if(top<1) return TRUE;
   if(i[top]<i[top-1]) return FALSE;
@@ -652,5 +689,6 @@
 }
 
-sorted_pair_node**  spn_merge(sorted_pair_node** p, int pn,sorted_pair_node **q, int qn,slimgb_alg* c){
+sorted_pair_node**  spn_merge(sorted_pair_node** p, int pn,sorted_pair_node **q, int qn,slimgb_alg* c)
+{
   int i;
   int* a= (int*) omalloc(qn*sizeof(int));
@@ -659,5 +697,4 @@
 //   for(mc=0;mc<qn;mc++)
 // {
-
 //     wrp(q[mc]->lcm_of_lm);
 //     PrintS("\n");
@@ -666,20 +703,21 @@
 //   for(mc=0;mc<pn;mc++)
 // {
-
 //     wrp(p[mc]->lcm_of_lm);
 //     PrintS("\n");
 // }
   int lastpos=0;
-  for(i=0;i<qn;i++){
+  for(i=0;i<qn;i++)
+  {
     lastpos=posInPairs(p,pn,q[i],c, si_max(lastpos-1,0));
     //   cout<<lastpos<<"\n";
     a[i]=lastpos;
-
-  }
-  if((pn+qn)>c->max_pairs){
+  }
+  if((pn+qn)>c->max_pairs)
+  {
     p=(sorted_pair_node**) omrealloc(p,2*(pn+qn)*sizeof(sorted_pair_node*));
     c->max_pairs=2*(pn+qn);
   }
-  for(i=qn-1;i>=0;i--){
+  for(i=qn-1;i>=0;i--)
+  {
     size_t size;
     if(qn-1>i)
@@ -694,11 +732,8 @@
 }
 
-
-static BOOLEAN trivial_syzygie(int pos1,int pos2,poly bound,slimgb_alg* c){
-
-
+static BOOLEAN trivial_syzygie(int pos1,int pos2,poly bound,slimgb_alg* c)
+{
   poly p1=c->S->m[pos1];
   poly p2=c->S->m[pos2];
-
 
   if (pGetComp(p1) > 0 || pGetComp(p2) > 0)
@@ -710,11 +745,9 @@
 
   if((gcd1!=NULL) && (gcd2!=NULL))
-    {
-      gcd1->next=gcd2; //may ordered incorrect
-      m=gcd_of_terms(gcd1,c->r);
-      gcd1->next=NULL;
-
-    }
-
+  {
+    gcd1->next=gcd2; //may ordered incorrect
+    m=gcd_of_terms(gcd1,c->r);
+    gcd1->next=NULL;
+  }
   if (m==NULL)
   {
@@ -722,5 +755,6 @@
       {
   if (pGetExp(p1, i)+ pGetExp(p2, i) > pGetExp(bound,i))   return FALSE;
-  if (i == pVariables){
+  if (i == pVariables)
+  {
     //PrintS("trivial");
     return TRUE;
@@ -736,5 +770,6 @@
     pDelete(&m);
     return FALSE;}
-  if (i == pVariables){
+  if (i == pVariables)
+  {
     pDelete(&m);
     //PrintS("trivial");
@@ -744,33 +779,31 @@
       }
   }
-
-
-
-
 }
 
 //! returns position sets w as weight
-int find_best(red_object* r,int l, int u, wlen_type &w, slimgb_alg* c){
+int find_best(red_object* r,int l, int u, wlen_type &w, slimgb_alg* c)
+{
   int best=l;
   int i;
   w=r[l].guess_quality(c);
-  for(i=l+1;i<=u;i++){
+  for(i=l+1;i<=u;i++)
+  {
     wlen_type w2=r[i].guess_quality(c);
-    if(w2<w){
+    if(w2<w)
+    {
       w=w2;
       best=i;
     }
-
   }
  return best;
 }
 
-
-void red_object::canonicalize(){
+void red_object::canonicalize()
+{
   kBucketCanonicalize(bucket);
-
-
-}
-BOOLEAN good_has_t_rep(int i, int j,slimgb_alg* c){
+}
+
+BOOLEAN good_has_t_rep(int i, int j,slimgb_alg* c)
+{
   assume(i>=0);
     assume(j>=0);
@@ -787,10 +820,10 @@
   //p_Delete(&lm,c->r);
 
-
-  for (int n=0;((n<c->n) && (i_con[n]>=0));n++){
-    if (i_con[n]==j){
+  for (int n=0;((n<c->n) && (i_con[n]>=0));n++)
+  {
+    if (i_con[n]==j)
+    {
       now_t_rep(i,j,c);
       omfree(i_con);
-
       return TRUE;
     }
@@ -800,7 +833,9 @@
   return FALSE;
 }
-BOOLEAN lenS_correct(kStrategy strat){
+BOOLEAN lenS_correct(kStrategy strat)
+{
   int i;
-  for(i=0;i<=strat->sl;i++){
+  for(i=0;i<=strat->sl;i++)
+  {
     if (strat->lenS[i]!=pLength(strat->S[i]))
       return FALSE;
@@ -841,8 +876,10 @@
   }
 }
-static int bucket_guess(kBucket* bucket){
+static int bucket_guess(kBucket* bucket)
+{
   int sum=0;
   int i;
-  for (i=bucket->buckets_used;i>=0;i--){
+  for (i=bucket->buckets_used;i>=0;i--)
+  {
     if(bucket->buckets[i])
        sum+=bucket->buckets_length[i];
@@ -850,9 +887,4 @@
   return sum;
 }
-
-
-
-
-
 
 static int add_to_reductors(slimgb_alg* c, poly h, int len, int ecart, BOOLEAN simplified)
@@ -888,6 +920,4 @@
   c->strat->enterS(P,i,c->strat,-1);
 
-
-
   c->strat->lenS[i]=len;
   assume(pLength(c->strat->S[i])==c->strat->lenS[i]);
@@ -896,6 +926,6 @@
 
   return i;
-
-}
+}
+
 static void length_one_crit(slimgb_alg* c, int pos, int len)
 {
@@ -910,5 +940,6 @@
         c->states[pos][i]=HASTREP;
     }
-    for ( i=pos+1;i<c->n;i++){
+    for ( i=pos+1;i<c->n;i++)
+    {
       if (c->lengths[i]==1)
         c->states[i][pos]=HASTREP;
@@ -918,5 +949,4 @@
   }
 }
-
 
 static void move_forward_in_S(int old_pos, int new_pos,kStrategy strat)
@@ -1010,13 +1040,15 @@
   int pos;
 
-  while(TRUE){
-    if ((con_checked<connected_length)&& (not_yet_found>0)){
+  while(TRUE)
+  {
+    if ((con_checked<connected_length)&& (not_yet_found>0))
+    {
       pos=connected[con_checked];
-      for(int i=0;i<cans_length;i++){
+      for(int i=0;i<cans_length;i++)
+      {
         if (cans[i]<0) continue;
         //FIXME: triv. syz. does not hold on noncommutative, check it for modules
         if ((has_t_rep(pos,cans[i],c)) ||((!rIsPluralRing(c->r))&&(trivial_syzygie(pos,cans[i],bound,c))))
 {
-
           connected[connected_length]=cans[i];
           connected_length++;
@@ -1024,6 +1056,8 @@
           --not_yet_found;
 
-          if (connected[connected_length-1]==to){
-            if (connected_length<c->n){
+          if (connected[connected_length-1]==to)
+	  {
+            if (connected_length<c->n)
+	    {
               connected[connected_length]=-1;
             }
@@ -1037,7 +1071,10 @@
     else
     {
-      for(last_cans_pos++;last_cans_pos<=c->n;last_cans_pos++){
-        if (last_cans_pos==c->n){
-          if (connected_length<c->n){
+      for(last_cans_pos++;last_cans_pos<=c->n;last_cans_pos++)
+      {
+        if (last_cans_pos==c->n)
+	{
+          if (connected_length<c->n)
+	  {
             connected[connected_length]=-1;
           }
@@ -1047,5 +1084,6 @@
         if ((last_cans_pos==from)||(last_cans_pos==to))
           continue;
-        if(p_LmShortDivisibleBy(I->m[last_cans_pos],c->short_Exps[last_cans_pos],bound,neg_bounds_short,c->r)){
+        if(p_LmShortDivisibleBy(I->m[last_cans_pos],c->short_Exps[last_cans_pos],bound,neg_bounds_short,c->r))
+	{
           cans[cans_length]=last_cans_pos;
           cans_length++;
@@ -1054,17 +1092,18 @@
       }
       not_yet_found++;
-      for (int i=0;i<con_checked;i++){
-        if (has_t_rep(connected[i],last_cans_pos,c)){
-
+      for (int i=0;i<con_checked;i++)
+      {
+        if (has_t_rep(connected[i],last_cans_pos,c))
+	{
           connected[connected_length]=last_cans_pos;
           connected_length++;
           cans[cans_length-1]=-1;
-
           --not_yet_found;
-          if (connected[connected_length-1]==to){
-            if (connected_length<c->n){
+          if (connected[connected_length-1]==to)
+	  {
+            if (connected_length<c->n)
+	    {
               connected[connected_length]=-1;
             }
-
             omfree(cans);
             return connected;
@@ -1075,8 +1114,8 @@
     }
   }
-  if (connected_length<c->n){
+  if (connected_length<c->n)
+  {
     connected[connected_length]=-1;
   }
-
   omfree(cans);
   return connected;
@@ -1118,8 +1157,10 @@
   int* j_con =make_connections(j,i,lm,c);
 
-//   if(c->n>1){
+//   if(c->n>1)
+//   {
 //     if (i_con[1]>=0)
 //       i=i_con[1];
-//     else {
+//     else
+//     {
 //       if (j_con[1]>=0)
 //         j=j_con[1];
@@ -1127,13 +1168,14 @@
  // }
 
-  int sugar=c->pTotaldegree(lm);
+  int sugar=syz_deg=c->pTotaldegree(lm);
+
   p_Delete(&lm, c->r);
-  if(c->T_deg_full)//Sugar
-  {
-    int t_i=c->T_deg_full[i]-c->T_deg[i];
-    int t_j=c->T_deg_full[j]-c->T_deg[j];
-    sugar+=si_max(t_i,t_j);
-    //Print("\n max: %d\n",max(t_i,t_j));
-  }
+    if(c->T_deg_full)//Sugar
+    {
+      int t_i=c->T_deg_full[i]-c->T_deg[i];
+      int t_j=c->T_deg_full[j]-c->T_deg[j];
+      sugar+=si_max(t_i,t_j);
+      //Print("\n max: %d\n",max(t_i,t_j));
+    }
 
   for (int m=0;((m<c->n) && (i_con[m]>=0));m++)
@@ -1146,21 +1188,20 @@
     if (c->weighted_lengths[i_con[m]]<c->weighted_lengths[i])
         i=i_con[m];
-  }
-  for (int m=0;((m<c->n) && (j_con[m]>=0));m++)
-  {
-    if (c->T_deg_full!=NULL)
-    {
-      int s1=c->T_deg_full[j_con[m]]+syz_deg-c->T_deg[j_con[m]];
-      if (s1>sugar) continue;
-    }
-    if (c->weighted_lengths[j_con[m]]<c->weighted_lengths[j])
-      j=j_con[m];
-  }
-
-  //can also try dependend search
+    }
+    for (int m=0;((m<c->n) && (j_con[m]>=0));m++)
+    {
+        if (c->T_deg_full!=NULL)
+	{
+        int s1=c->T_deg_full[j_con[m]]+syz_deg-c->T_deg[j_con[m]];
+        if (s1>sugar) continue;}
+        if (c->weighted_lengths[j_con[m]]<c->weighted_lengths[j])
+            j=j_con[m];
+    }
+
+     //can also try dependend search
   omfree(i_con);
   omfree(j_con);
-}
-
+  return;
+}
 
 static void add_later(poly p, const char* prot, slimgb_alg* c)
@@ -1168,5 +1209,4 @@
     int i=0;
     //check, if it is already in the queue
-
 
     while(c->add_later->m[i]!=NULL)
@@ -1182,10 +1222,7 @@
 static int simple_posInS (kStrategy strat, poly p,int len, wlen_type wlen)
 {
-
-
   if(strat->sl==-1) return 0;
   if (strat->lenSw) return pos_helper(strat,p,(wlen_type) wlen,(wlen_set) strat->lenSw,strat->S);
   return pos_helper(strat,p,len,strat->lenS,strat->S);
-
 }
 
@@ -1210,6 +1247,4 @@
 }
 
-
-
 static int iq_crit(const void* ap,const void* bp)
 {
@@ -1218,5 +1253,4 @@
   assume(a->i>a->j);
   assume(b->i>b->j);
-
 
   if (a->deg<b->deg) return -1;
@@ -1231,9 +1265,11 @@
   return 0;
 }
-static wlen_type coeff_mult_size_estimate(int s1, int s2, ring r){
+static wlen_type coeff_mult_size_estimate(int s1, int s2, ring r)
+{
     if (rField_is_Q(r)) return s1+s2;
     else return s1*s2;
 }
-static wlen_type pair_weighted_length(int i, int j, slimgb_alg* c){
+static wlen_type pair_weighted_length(int i, int j, slimgb_alg* c)
+{
     if ((c->isDifficultField) && (c->eliminationProblem))  {
         int c1=slim_nsize(p_GetCoeff(c->S->m[i],c->r),c->r);
@@ -1255,5 +1291,6 @@
         //int cs=slim_nsize(p_GetCoeff(c->S->m[i],c->r),c->r)+
         //    slim_nsize(p_GetCoeff(c->S->m[j],c->r),c->r);
-        if(!(TEST_V_COEFSTRAT)){
+        if(!(TEST_V_COEFSTRAT))
+	{
         wlen_type cs=
             coeff_mult_size_estimate(
@@ -1262,5 +1299,6 @@
         return (wlen_type)(c->lengths[i]+c->lengths[j]-2)*
             (wlen_type)cs;}
-            else {
+            else
+	    {
 
             wlen_type cs=
@@ -1293,5 +1331,6 @@
          poly div_by=pDivide(copy, got);
          poly iter=h;
-         while(iter){
+         while(iter)
+	 {
             pExpVectorSub(iter,div_by);
             pIter(iter);
@@ -1336,5 +1375,4 @@
     //}
     //ENLARGE(c->S->m,poly);
-
   }
   pEnlargeSet(&c->S->m,c->n-1,1);
@@ -1348,11 +1386,7 @@
     assume(ecart>=0);
   }
-
-
   c->tmp_pair_lm[i]=pOne_Special(c->r);
 
-
   c->tmp_spn[i]=(sorted_pair_node*) omalloc(sizeof(sorted_pair_node));
-
 
   c->lengths[i]=pLength(h);
@@ -1364,5 +1398,4 @@
     p_Cleardenom(h, c->r);
     //p_Content(h,c->r); //is a duplicate call, but belongs here
-
   }
   else
@@ -1379,5 +1412,4 @@
 
     c->states.push_back(vector<bool>(i));
-
 
   #else
@@ -1393,6 +1425,8 @@
 
 #undef ENLARGE
-  if (p_GetComp(h,currRing)<=c->syz_comp){
-  for (j=0;j<i;j++){
+  if (p_GetComp(h,currRing)<=c->syz_comp)
+  {
+  for (j=0;j<i;j++)
+  {
 
 
@@ -1403,14 +1437,15 @@
      p_LmShortDivisibleBy(c->S->m[i],c->short_Exps[i],c->S->m[j],~(c->short_Exps[j]),c->r));
 
-
-    if (_p_GetComp(c->S->m[i],c->r)!=_p_GetComp(c->S->m[j],c->r)){
+    if (_p_GetComp(c->S->m[i],c->r)!=_p_GetComp(c->S->m[j],c->r))
+    {
       //c->states[i][j]=UNCALCULATED;
       //WARNUNG: be careful
       continue;
-    } else
-    if ((!c->nc) && (c->lengths[i]==1) && (c->lengths[j]==1)){
+    }
+    else
+    if ((!c->nc) && (c->lengths[i]==1) && (c->lengths[j]==1))
+    {
       c->states[i][j]=HASTREP;
-
-      }
+    }
     else if (( (!c->nc) || (c->is_homog && rIsSCA(c->r) ) ) &&  (pHasNotCF(c->S->m[i],c->S->m[j])))
 //     else if ((!(c->nc)) &&  (pHasNotCF(c->S->m[i],c->S->m[j])))
@@ -1424,21 +1459,25 @@
       c->states[i][j]=HASTREP;
       c->extended_product_crit++;
-
       //PrintS("E");
     }
-      //  if (c->states[i][j]==UNCALCULATED){
+      //  if (c->states[i][j]==UNCALCULATED)
+      //  {
 
     if ((TEST_V_FINDMONOM) &&(!c->nc)) {
         //PrintS("COMMU");
-       //  if (c->lengths[i]==c->lengths[j]){
+       //  if (c->lengths[i]==c->lengths[j])
+       //  {
 //             poly short_s=ksCreateShortSpoly(c->S->m[i],c->S->m[j],c->r);
-//             if (short_s==NULL){
+//             if (short_s==NULL)
+//             {
 //                 c->states[i][j]=HASTREP;
-//             } else
+//             }
+//             else
 //             {
 //                 p_Delete(&short_s, currRing);
 //             }
 //         }
-        if (c->lengths[i]+c->lengths[j]==3){
+        if (c->lengths[i]+c->lengths[j]==3)
+	{
 
 
@@ -1468,10 +1507,12 @@
                 else
                 {
-                    if (c->strat->lenS[iS]>1){
+                    if (c->strat->lenS[iS]>1)
+		    {
                         //PrintS("O");
                         if (TRUE) {
                         c->states[i][j]=HASTREP;
                         add_later(short_s,"O",c);
-                        } else p_Delete(&short_s,currRing);
+                        }
+			else p_Delete(&short_s,currRing);
                     }
                     else
@@ -1522,7 +1563,4 @@
   }//if syz_comp end
 
-
-
-
   assume(spc<=i);
   //now ideal quotient crit
@@ -1541,8 +1579,8 @@
       if(!pLmEqual(nodes[lower]->lcm_of_lm,nodes[upper]->lcm_of_lm))
       {
-        break;
+  break;
       }
       if (has_t_rep(nodes[upper]->i,nodes[upper]->j,c))
-        has=TRUE;
+  has=TRUE;
     }
     upper=upper-1;
@@ -1592,7 +1630,4 @@
   //  Print("i:%d,spc_final:%d",i,spc_final);
 
-
-
-
   assume(spc_final<=spc);
   omfree(nodes);
@@ -1601,5 +1636,6 @@
   add_to_reductors(c, h, c->lengths[c->n-1], ecart,TRUE);
   //i=posInS(c->strat,c->strat->sl,h,0 ecart);
-  if (!(c->nc)){
+  if (!(c->nc))
+  {
     if (c->lengths[c->n-1]==1)
       shorten_tails(c,c->S->m[c->n-1]);
@@ -1656,5 +1692,6 @@
 
 
-  if(!ip){
+  if(!ip)
+  {
     qsort(nodes_final,spc_final,sizeof(sorted_pair_node*),tgb_pair_better_gen2);
 
@@ -1670,9 +1707,5 @@
     return nodes_final;
   }
-
-
-
-}
-
+}
 
 static poly redNF2 (poly h,slimgb_alg* c , int &len, number&  m,int n)
@@ -1758,9 +1791,9 @@
 }
 
-
-
-static poly redTailShort(poly h, kStrategy strat){
+static poly redTailShort(poly h, kStrategy strat)
+{
   if (h==NULL) return NULL;//n_Init(1,currRing);
-  if (TEST_V_MODPSOLVSB){
+  if (TEST_V_MODPSOLVSB)
+  {
     bit_reduce(pNext(h), strat->tailRing);
   }
@@ -1768,5 +1801,6 @@
   int i;
   int len=pLength(h);
-  for(i=0;i<=strat->sl;i++){
+  for(i=0;i<=strat->sl;i++)
+  {
     if((strat->lenS[i]>2) || ((strat->lenSw!=NULL) && (strat->lenSw[i]>2)))
       break;
@@ -1775,5 +1809,6 @@
 }
 
-static void line_of_extended_prod(int fixpos,slimgb_alg* c){
+static void line_of_extended_prod(int fixpos,slimgb_alg* c)
+{
     if (c->gcd_of_terms[fixpos]==NULL)
   {
@@ -1796,5 +1831,6 @@
   }
 }
-static void c_S_element_changed_hook(int pos, slimgb_alg* c){
+static void c_S_element_changed_hook(int pos, slimgb_alg* c)
+{
   length_one_crit(c,pos, c->lengths[pos]);
   if (!c->nc)
@@ -1807,5 +1843,6 @@
   poly_tree_node* r;
   int n;
-  poly_tree_node(int sn):l(NULL),r(NULL),n(sn){}
+  poly_tree_node(int sn):l(NULL),r(NULL),n(sn)
+  {}
 };
 class exp_number_builder{
@@ -1814,9 +1851,12 @@
   int n;
   int get_n(poly p);
-  exp_number_builder():top_level(0),n(0){}
+  exp_number_builder():top_level(0),n(0)
+  {}
 };
-int exp_number_builder::get_n(poly p){
+int exp_number_builder::get_n(poly p)
+{
   poly_tree_node** node=&top_level;
-  while(*node!=NULL){
+  while(*node!=NULL)
+  {
     int c=pLmCmp(p,(*node)->p);
     if (c==0) return (*node)->n;
@@ -1842,5 +1882,6 @@
 
 //! obsolete
-void t2ippa_rec(poly* ip,int* ia, poly_tree_node* k, int &offset){
+void t2ippa_rec(poly* ip,int* ia, poly_tree_node* k, int &offset)
+{
     if(!k) return;
     t2ippa_rec(ip,ia,k->l,offset);
@@ -1854,14 +1895,17 @@
 
 //! obsolete
-void t2ippa(poly* ip,int* ia,exp_number_builder & e){
+void t2ippa(poly* ip,int* ia,exp_number_builder & e)
+{
 
   int o=0;
   t2ippa_rec(ip,ia,e.top_level,o);
 }
-int anti_poly_order(const void* a, const void* b){
+int anti_poly_order(const void* a, const void* b)
+{
   return -pLmCmp(((int_poly_pair*) a)->p,((int_poly_pair*) b)->p );
 }
 
-BOOLEAN is_valid_ro(red_object & ro){
+BOOLEAN is_valid_ro(red_object & ro)
+{
   red_object r2=ro;
   ro.validate();
@@ -1869,13 +1913,17 @@
   return TRUE;
 }
-int terms_sort_crit(const void* a, const void* b){
+int terms_sort_crit(const void* a, const void* b)
+{
   return -pLmCmp(*((poly*) a),*((poly*) b));
 }
-static void unify_terms(poly* terms,int & sum){
+static void unify_terms(poly* terms,int & sum)
+{
   if (sum==0) return;
   int last=0;
   int curr=1;
-  while(curr<sum){
-    if (!(pLmEqual(terms[curr],terms[last]))){
+  while(curr<sum)
+  {
+    if (!(pLmEqual(terms[curr],terms[last])))
+    {
       terms[++last]=terms[curr];
     }
@@ -1884,5 +1932,6 @@
   sum=last+1;
 }
-static void export_mat(number* number_array,int pn, int tn,const char* format_str, int mat_nr){
+static void export_mat(number* number_array,int pn, int tn,const char* format_str, int mat_nr)
+{
   char matname[20];
   sprintf(matname,format_str,mat_nr);
@@ -1890,5 +1939,6 @@
   int i,j;
   fprintf(out,"mat=[\n");
-  for(i=0;i<pn;i++){
+  for(i=0;i<pn;i++)
+  {
     fprintf(out,"[\n");
     for(j=0;j<tn;j++)
@@ -1913,5 +1963,6 @@
 #ifdef USE_NORO
 #ifndef NORO_CACHE
-static void linalg_step_modp(poly *p, poly* p_out, int& pn, poly* terms,int tn, slimgb_alg* c){
+static void linalg_step_modp(poly *p, poly* p_out, int& pn, poly* terms,int tn, slimgb_alg* c)
+{
   static int export_n=0;
   assume(terms[tn-1]!=NULL);
@@ -1922,8 +1973,10 @@
   number_type* number_array=(number_type*) omalloc(pn*tn*sizeof(number_type));
   int i;
-  for(i=0;i<array_size;i++){
+  for(i=0;i<array_size;i++)
+  {
     number_array[i]=zero;
   }
-  for(i=0;i<pn;i++){
+  for(i=0;i<pn;i++)
+  {
     poly h=p[i];
     //int base=tn*i;
@@ -1939,5 +1992,6 @@
   int act_row=0;
   int p_pos=0;
-  for(i=0;i<pn;i++){
+  for(i=0;i<pn;i++)
+  {
     poly h=NULL;
     int j;
@@ -1953,5 +2007,6 @@
   pn=p_pos;
   //assert(p_pos==rank)
-  while(p_pos<pn){
+  while(p_pos<pn)
+  {
     p_out[p_pos++]=NULL;
   }
@@ -1962,14 +2017,17 @@
 #endif
 #endif
-static void mass_add(poly* p, int pn,slimgb_alg* c){
+static void mass_add(poly* p, int pn,slimgb_alg* c)
+{
     int j;
     int* ibuf=(int*) omalloc(pn*sizeof(int));
     sorted_pair_node*** sbuf=(sorted_pair_node***) omalloc(pn*sizeof(sorted_pair_node**));
-    for(j=0;j<pn;j++){
+    for(j=0;j<pn;j++)
+    {
       p_Test(p[j],c->r);
       sbuf[j]=add_to_basis_ideal_quotient(p[j],c,ibuf+j);
     }
     int sum=0;
-    for(j=0;j<pn;j++){
+    for(j=0;j<pn;j++)
+    {
       sum+=ibuf[j];
     }
@@ -2003,9 +2061,11 @@
 #ifdef NORO_CACHE
 #ifndef NORO_NON_POLY
-void NoroCache::evaluateRows(){
+void NoroCache::evaluateRows()
+{
   //after that can evaluate placeholders
   int i;
   buffer=(number*) omalloc(nIrreducibleMonomials*sizeof(number));
-  for(i=0;i<root.branches_len;i++){
+  for(i=0;i<root.branches_len;i++)
+  {
     evaluateRows(1,root.branches[i]);
   }
@@ -2013,15 +2073,21 @@
   buffer=NULL;
 }
-void NoroCache::evaluateRows(int level, NoroCacheNode* node){
+void NoroCache::evaluateRows(int level, NoroCacheNode* node)
+{
   assume(level>=0);
   if (node==NULL) return;
-  if (level<pVariables){
+  if (level<pVariables)
+  {
     int i,sum;
-    for(i=0;i<node->branches_len;i++){
+    for(i=0;i<node->branches_len;i++)
+    {
       evaluateRows(level+1,node->branches[i]);
     }
-  } else {
+  }
+  else
+  {
     DataNoroCacheNode* dn=(DataNoroCacheNode*) node;
-    if (dn->value_len!=backLinkCode){
+    if (dn->value_len!=backLinkCode)
+    {
       poly p=dn->value_poly;
       #ifndef NORO_SPARSE_ROWS_PRE
@@ -2034,5 +2100,6 @@
       int idx;
       number* a=buffer;
-      while(p){
+      while(p)
+      {
         DataNoroCacheNode* ref=getCacheReference(p);
 
@@ -2054,5 +2121,6 @@
       SparseRow* row=dn->row;
       int i=0;
-      while(p){
+      while(p)
+      {
         DataNoroCacheNode* ref=getCacheReference(p);
 
@@ -2061,27 +2129,31 @@
         row->idx_array[i]=idx;
         row->coef_array[i]=p_GetCoeff(p,currRing);
-
         i++;
         pIter(p);
       }
-      if (i!=dn->value_len){
+      if (i!=dn->value_len)
+      {
         PrintS("F4 calc wrong, as poly len was wrong\n");
       }
       assume(i==dn->value_len);
       #endif
-
-    }
-  }
-}
-
-void NoroCache::evaluatePlaceHolder(number* row,std::vector<NoroPlaceHolder>& place_holders){
+    }
+  }
+}
+
+void NoroCache::evaluatePlaceHolder(number* row,std::vector<NoroPlaceHolder>& place_holders)
+{
   int i;
   int s=place_holders.size();
-  for(i=0;i<s;i++){
+  for(i=0;i<s;i++)
+  {
     DataNoroCacheNode* ref=place_holders[i].ref;
     number coef=place_holders[i].coef;
-    if (ref->value_len==backLinkCode){
+    if (ref->value_len==backLinkCode)
+    {
       row[ref->term_index]=npAddM(row[ref->term_index],coef);
-    } else {
+    }
+    else
+    {
       #ifndef NORO_SPARSE_ROWS_PRE
       DenseRow* ref_row=ref->row;
@@ -2091,6 +2163,8 @@
       number* my_pos=row+ref_row->begin;
       //TODO npisOne distinction
-      if (!(npIsOne(coef))){
-        while(ref_begin!=ref_end){
+      if (!(npIsOne(coef)))
+      {
+        while(ref_begin!=ref_end)
+	{
 
           *my_pos=npAddM(*my_pos,npMult(coef,*ref_begin));
@@ -2099,6 +2173,8 @@
         }
       }
-      else{
-        while(ref_begin!=ref_end){
+      else
+      {
+        while(ref_begin!=ref_end)
+	{
 
           *my_pos=npAddM(*my_pos,*ref_begin);
@@ -2107,6 +2183,4 @@
         }
       }
-
-
 
     #else
@@ -2117,5 +2191,6 @@
     int* idx_array=ref_row->idx_array;
     number* coef_array=ref_row->coef_array;
-    for(j=0;j<n;j++){
+    for(j=0;j<n;j++)
+    {
       int idx=idx_array[j];
       number ref_coef=coef_array[j];
@@ -2125,27 +2200,25 @@
   }
   }
-
 }
 #endif
 
-
-
 //poly noro_red_non_unique(poly p, int &len, NoroCache* cache,slimgb_alg* c);
 
-
 #ifndef NORO_NON_POLY
-MonRedRes noro_red_mon(poly t, BOOLEAN force_unique, NoroCache* cache,slimgb_alg* c){
+MonRedRes noro_red_mon(poly t, BOOLEAN force_unique, NoroCache* cache,slimgb_alg* c)
+{
   MonRedRes res_holder;
 
   //wrp(t);
   res_holder.changed=TRUE;
-  if (force_unique){
+  if (force_unique)
+  {
     DataNoroCacheNode* ref=cache->getCacheReference(t);
-    if (ref!=NULL){
+    if (ref!=NULL)
+    {
       res_holder.len=ref->value_len;
-      if (res_holder.len==NoroCache::backLinkCode){
+      if (res_holder.len==NoroCache::backLinkCode)
+      {
         res_holder.len=1;
-
-
       }
       res_holder.coef=p_GetCoeff(t,c->r);
@@ -2157,9 +2230,13 @@
       return res_holder;
     }
-  } else{
+  }
+  else
+  {
     BOOLEAN succ;
     poly cache_lookup=cache->lookup(t,succ, res_holder.len);//don't own this yet
-    if (succ){
-      if (cache_lookup==t){
+    if (succ)
+    {
+      if (cache_lookup==t)
+      {
       //know they are equal
       //res_holder.len=1;
@@ -2212,5 +2289,4 @@
       //p_Delete(&t_copy_mon,c->r);
       //res=pMult_nn(res,coef_bak);
-
     res_holder.changed=TRUE;
     res_holder.p=res;
@@ -2219,11 +2295,13 @@
     res_holder.ref=ref;
     return res_holder;
-
-  } else {
+  }
+  else
+  {
     number coef_bak=p_GetCoeff(t,c->r);
     number one=npInit(1);
     p_SetCoeff(t,one,c->r);
     res_holder.len=1;
-    if (!(force_unique)){
+    if (!(force_unique))
+    {
       res_holder.ref=cache->insert(t,t,res_holder.len);
       p_SetCoeff(t,coef_bak,c->r);
@@ -2237,5 +2315,7 @@
       res_holder.onlyBorrowed=FALSE;
       return res_holder;
-    } else {
+    }
+    else
+    {
       res_holder.ref=cache->insertAndTransferOwnerShip(t,c->r);
       res_holder.coef=coef_bak;
@@ -2252,5 +2332,6 @@
 #ifndef NORO_NON_POLY
 //len input and out: Idea: reverse addition
-poly noro_red_non_unique(poly p, int &len, NoroCache* cache,slimgb_alg* c){
+poly noro_red_non_unique(poly p, int &len, NoroCache* cache,slimgb_alg* c)
+{
   assume(len==pLength(p));
   poly orig_p=p;
@@ -2265,5 +2346,6 @@
   int unchanged_size=0;
 
-  while(p){
+  while(p)
+  {
     poly t=p;
     pIter(p);
@@ -2273,23 +2355,34 @@
 #endif
     MonRedRes red=noro_red_mon(t,FALSE,cache,c);
-    if ((!(red.changed))&&(!(red.onlyBorrowed))){
+    if ((!(red.changed))&&(!(red.onlyBorrowed)))
+    {
       unchanged_size++;
       assume(npIsOne(red.coef));
       assume(p_GetCoeff(red.p,currRing)==coef_debug);
-      if (unchanged_head){
+      if (unchanged_head)
+      {
         pNext(unchanged_tail)=red.p;
         pIter(unchanged_tail);
-      } else{
+      }
+      else
+      {
         unchanged_tail=red.p;
         unchanged_head=red.p;
       }
-    } else{
+    }
+    else
+    {
       assume(red.len==pLength(red.p));
-      if (red.onlyBorrowed){
-        if (npIsOne(red.coef)){
+      if (red.onlyBorrowed)
+      {
+        if (npIsOne(red.coef))
+	{
           t=p_Copy(red.p,currRing);
-        }else
+        }
+	else
         t=pp_Mult_nn(red.p,red.coef,currRing);
-      } else {
+      }
+      else
+      {
         if (npIsOne(red.coef))
         t=red.p;
@@ -2305,8 +2398,4 @@
   kBucketClear(bucket,&res,&len);
   kBucketDestroy(&bucket);
-
-
-
-
   return res;
 }
@@ -2315,11 +2404,18 @@
 //len input and out: Idea: reverse addition
 
-/*template <class number_type> SparseRow<number_type>* noro_red_to_non_poly(poly p, int &len, NoroCache<number_type>* cache,slimgb_alg* c){
-  if (npPrimeM<255){
+/*template <class number_type> SparseRow<number_type>* noro_red_to_non_poly(poly p, int &len, NoroCache<number_type>* cache,slimgb_alg* c)
+ * {
+  if (npPrimeM<255)
+  {
     return noro_red_to_non_poly_t<tgb_uint8>(p,len,cache,c);
-  } else {
-    if (npPrimeM<65000){
+  }
+  else
+  {
+    if (npPrimeM<65000)
+    {
       return noro_red_to_non_poly_t<tgb_uint16>(p,len,cache,c);
-    } else{
+    }
+    else
+    {
       return noro_red_to_non_poly_t<tgb_uint32>(p,len,cache,c);
     }
@@ -2329,7 +2425,9 @@
 //len input and out: Idea: reverse addition
 #ifndef NORO_NON_POLY
-std::vector<NoroPlaceHolder> noro_red(poly p, int &len, NoroCache* cache,slimgb_alg* c){
+std::vector<NoroPlaceHolder> noro_red(poly p, int &len, NoroCache* cache,slimgb_alg* c)
+{
   std::vector<NoroPlaceHolder> res;
-   while(p){
+   while(p)
+   {
       poly t=p;
       pIter(p);
@@ -2351,12 +2449,9 @@
 #endif
 
-
-
-
-
 #endif
 #ifdef USE_NORO
 #ifndef NORO_CACHE
-void noro_step(poly*p,int &pn,slimgb_alg* c){
+void noro_step(poly*p,int &pn,slimgb_alg* c)
+{
   poly* reduced=(poly*) omalloc(pn*sizeof(poly));
   int j;
@@ -2368,5 +2463,6 @@
   NoroCache cache;
 #endif
-  for(j=0;j<pn;j++){
+  for(j=0;j<pn;j++)
+  {
 
     poly h=p[j];
@@ -2380,5 +2476,6 @@
     assume(pLength(h)==h_len);
 #endif
-    if (h!=NULL){
+    if (h!=NULL)
+    {
 #ifndef NORO_CACHE
 
@@ -2386,6 +2483,4 @@
       h_len=pLength(h);
 #endif
-
-
       reduced[reduced_c]=h;
       reduced_len[reduced_c]=h_len;
@@ -2396,13 +2491,16 @@
   }
   int reduced_sum=0;
-  for(j=0;j<reduced_c;j++){
+  for(j=0;j<reduced_c;j++)
+  {
     reduced_sum+=reduced_len[j];
   }
   poly* terms=(poly*) omalloc(reduced_sum*sizeof(poly));
   int tc=0;
-  for(j=0;j<reduced_c;j++){
+  for(j=0;j<reduced_c;j++)
+  {
     poly h=reduced[j];
 
-    while(h!=NULL){
+    while(h!=NULL)
+    {
       terms[tc++]=h;
       pIter(h);
@@ -2430,9 +2528,8 @@
 #else
 
-
-
 #endif
 #endif
-static void go_on (slimgb_alg* c){
+static void go_on (slimgb_alg* c)
+{
   //set limit of 1000 for multireductions, at the moment for
   //programming reasons
@@ -2445,5 +2542,6 @@
   int i=0;
   c->average_length=0;
-  for(i=0;i<c->n;i++){
+  for(i=0;i<c->n;i++)
+  {
     c->average_length+=c->lengths[i];
   }
@@ -2459,11 +2557,12 @@
 
   int curr_deg=-1;
-  while(i<max_pairs){
+  while(i<max_pairs)
+  {
     sorted_pair_node* s=top_pair(c);//here is actually chain criterium done
 
-
     if (!s) break;
 
-    if(curr_deg>=0){
+    if(curr_deg>=0)
+    {
       if (s->deg >curr_deg) break;
     }
@@ -2471,5 +2570,6 @@
     else curr_deg=s->deg;
     quick_pop_pair(c);
-    if(s->i>=0){
+    if(s->i>=0)
+    {
       //be careful replace_pair use createShortSpoly which is not noncommutative
       now_t_rep(s->i,s->j,c);
@@ -2498,5 +2598,6 @@
     p_Test(h,c->r);
     }
-    else{
+    else
+    {
       h=s->lcm_of_lm;
       p_Test(h,c->r);
@@ -2507,5 +2608,6 @@
     int mlen=pLength(h);
     p_Test(h,c->r);
-    if ((!c->nc)&(!(use_noro))){
+    if ((!c->nc)&(!(use_noro)))
+    {
       h=redNF2(h,c,mlen,coef,2);
       redTailShort(h,c->strat);
@@ -2517,10 +2619,10 @@
     int len=pLength(h);
     p[i]=h;
-
     i++;
   }
   p[i]=NULL;
 //  pre_comp(p,i,c);
-  if(i==0){
+  if(i==0)
+  {
     omfree(p);
     return;
@@ -2534,26 +2636,30 @@
   int j;
 #ifdef USE_NORO
-  //if ((!(c->nc))&&(rField_is_Zp(c->r))){
-  if (use_noro){
+  //if ((!(c->nc))&&(rField_is_Zp(c->r)))
+  //{
+  if (use_noro)
+  {
     int pn=i;
     if (pn==0) {omfree(p);return;}
-
-    {
-
-      if (npPrimeM<255){
+    {
+      if (npPrimeM<255)
+      {
         noro_step<tgb_uint8>(p,pn,c);
-      } else {
-        if (npPrimeM<65000){
+      }
+      else
+      {
+        if (npPrimeM<65000)
+	{
           noro_step<tgb_uint16>(p,pn,c);
-        } else{
+        }
+	else
+	{
           noro_step<tgb_uint32>(p,pn,c);
         }
       }
-
-
-
-    }
-
-    //if (TEST_OPT_PROT){
+    }
+
+    //if (TEST_OPT_PROT)
+    //{
     //  Print("reported rank:%i\n",pn);
     //}
@@ -2562,5 +2668,6 @@
     return;
     /*if (TEST_OPT_PROT)
-      for(j=0;j<pn;j++){
+      for(j=0;j<pn;j++)
+      {
         p_wrp(p[j],c->r);
       }*/
@@ -2568,5 +2675,6 @@
 #endif
   red_object* buf=(red_object*) omalloc(i*sizeof(red_object));
-  for(j=0;j<i;j++){
+  for(j=0;j<i;j++)
+  {
     p_Test(p[j],c->r);
     buf[j].p=p[j];
@@ -2574,5 +2682,6 @@
     buf[j].bucket = kBucketCreate(currRing);
     p_Test(p[j],c->r);
-    if (c->eliminationProblem){
+    if (c->eliminationProblem)
+    {
         buf[j].sugar=c->pTotaldegree_full(p[j]);
     }
@@ -2596,5 +2705,6 @@
         PrintS("B");
     int e;
-    for(e=0;e<=c->pair_top;e++){
+    for(e=0;e<=c->pair_top;e++)
+    {
         if(c->apairs[e]->i<0) continue;
         assume(c->apairs[e]->j>=0);
@@ -2637,7 +2747,10 @@
     p_Test(p,c->r);
     //if (!c->nc) {
-      if ((c->tailReductions) ||(lies_in_last_dp_block(p,c))){
+      if ((c->tailReductions) ||(lies_in_last_dp_block(p,c)))
+      {
       p=redNFTail(p,c->strat->sl,c->strat, 0);
-      } else {
+      }
+      else
+      {
       p=redTailShort(p, c->strat);
       }
@@ -2651,10 +2764,4 @@
   omfree(add_those);
   omfree(buf);
-
-
-
-
-
-
 
   if (TEST_OPT_PROT)
@@ -2668,6 +2775,4 @@
   return;
 }
-
-
 
 #ifdef REDTAIL_S
@@ -2720,7 +2825,9 @@
             pTest(strat->S[j]);
 #ifdef HAVE_PLURAL
-            if (nc){
+            if (nc)
+	    {
               nc_BucketPolyRed_Z(P.bucket, strat->S[j], &coef);
-            } else
+            }
+	    else
 #endif
               coef=kBucketPolyRed(P.bucket,strat->S[j],
@@ -2780,10 +2887,12 @@
 
 //transfers ownership of m to mat
-void init_with_mac_poly(tgb_sparse_matrix* mat, int row, mac_poly m){
+void init_with_mac_poly(tgb_sparse_matrix* mat, int row, mac_poly m)
+{
   assume(mat->mp[row]==NULL);
   mat->mp[row]=m;
 #ifdef TGB_DEBUG
   mac_poly r=m;
-  while(r){
+  while(r)
+  {
     assume(r->exp<mat->columns);
     r=r->next;
@@ -2791,5 +2900,6 @@
 #endif
 }
-poly free_row_to_poly(tgb_sparse_matrix* mat, int row, poly* monoms, int monom_index){
+poly free_row_to_poly(tgb_sparse_matrix* mat, int row, poly* monoms, int monom_index)
+{
   poly p=NULL;
   poly* set_this=&p;
@@ -2807,18 +2917,8 @@
   }
   return p;
-
-}
-
-
-
-
-
-
-
-
-
-
-
-static int poly_crit(const void* ap1, const void* ap2){
+}
+
+static int poly_crit(const void* ap1, const void* ap2)
+{
   poly p1,p2;
   p1=*((poly*) ap1);
@@ -2833,5 +2933,7 @@
   return 0;
 }
-void slimgb_alg::introduceDelayedPairs(poly* pa,int s){
+
+void slimgb_alg::introduceDelayedPairs(poly* pa,int s)
+{
     if (s==0) return;
     sorted_pair_node** si_array=(sorted_pair_node**) omalloc(s* sizeof(sorted_pair_node*));
@@ -2857,5 +2959,4 @@
         //      c->apairs[n-1-i]=si;
         si_array[i]=si;
-
   }
 
@@ -2865,4 +2966,5 @@
   omfree(si_array);
 }
+
 slimgb_alg::slimgb_alg(ideal I, int syz_comp,BOOLEAN F4,int deg_pos)
 {
@@ -2932,16 +3034,17 @@
   pair_top=-1;
 
-  int nn=IDELEMS(I);
-  array_lengths=nn;
+  int n=IDELEMS(I);
+  array_lengths=n;
+
 
   i=0;
   this->n=0;
-  T_deg=(int*) omalloc(nn*sizeof(int));
+  T_deg=(int*) omalloc(n*sizeof(int));
   if(eliminationProblem)
-    T_deg_full=(int*) omalloc(nn*sizeof(int));
+    T_deg_full=(int*) omalloc(n*sizeof(int));
   else
     T_deg_full=NULL;
-  tmp_pair_lm=(poly*) omalloc(nn*sizeof(poly));
-  tmp_spn=(sorted_pair_node**) omalloc(nn*sizeof(sorted_pair_node*));
+  tmp_pair_lm=(poly*) omalloc(n*sizeof(poly));
+  tmp_spn=(sorted_pair_node**) omalloc(n*sizeof(sorted_pair_node*));
   lm_bin=omGetSpecBin(POLYSIZE + (r->ExpL_Size)*sizeof(long));
 #ifdef HEAD_BIN
@@ -2952,5 +3055,5 @@
   #ifdef USE_STDVECBOOL
   #else
-  h=omalloc(nn*sizeof(char*));
+  h=omalloc(n*sizeof(char*));
 
   states=(char**) h;
@@ -2959,10 +3062,10 @@
   h=omalloc(n*sizeof(int));
   lengths=(int*) h;
-  weighted_lengths=(wlen_type*)omalloc(nn*sizeof(wlen_type));
-  gcd_of_terms=(poly*) omalloc(nn*sizeof(poly));
-
-  short_Exps=(long*) omalloc(nn*sizeof(long));
+  weighted_lengths=(wlen_type*)omalloc(n*sizeof(wlen_type));
+  gcd_of_terms=(poly*) omalloc(n*sizeof(poly));
+
+  short_Exps=(long*) omalloc(n*sizeof(long));
   if (F4_mode)
-    S=idInit(nn,I->rank);
+    S=idInit(n,I->rank);
   else
     S=idInit(1,I->rank);
@@ -2977,5 +3080,5 @@
   strat->enterS = enterSBba;
   strat->sl = -1;
-  i=nn;
+  i=n;
   i=1;//some strange bug else
   /* initS(c->S,NULL,c->strat); */
@@ -2995,5 +3098,5 @@
     strat->lenSw=NULL;
   sorted_pair_node* si;
-  assume(nn>0);
+  assume(n>0);
   add_to_basis_ideal_quotient(I->m[0],this,NULL);
 
@@ -3001,8 +3104,8 @@
   if(!(F4_mode))
   {
-    poly* array_arg=I->m;
-    array_arg++;
-    introduceDelayedPairs(array_arg,n-1);
-    /*
+        poly* array_arg=I->m;
+        array_arg++;
+        introduceDelayedPairs(array_arg,n-1);
+        /*
     for (i=1;i<n;i++)//the 1 is wanted, because first element is added to basis
     {
@@ -3019,13 +3122,12 @@
       si->lcm_of_lm=I->m[i];
 
-      //      c->apairs[nn-1-i]=si;
-      apairs[nn-i-1]=si;
+      //      c->apairs[n-1-i]=si;
+      apairs[n-i-1]=si;
       ++(pair_top);
-    }
-    */
+    }*/
   }
   else
   {
-    for (i=1;i<nn;i++)//the 1 is wanted, because first element is added to basis
+    for (i=1;i<n;i++)//the 1 is wanted, because first element is added to basis
       add_to_basis_ideal_quotient(I->m[i],this,NULL);
   }
@@ -3052,40 +3154,41 @@
 slimgb_alg::~slimgb_alg()
 {
+
   if (!(completed))
   {
-    poly* add=(poly*) omalloc((pair_top+2)*sizeof(poly));
-    int piter;
-    int pos=0;
-    for(piter=0;piter<=pair_top;piter++)
-    {
-      sorted_pair_node* s=apairs[piter];
-      if (s->i<0)
-      {
-        //delayed element
-        if (s->lcm_of_lm!=NULL)
-        {
-          add[pos]=s->lcm_of_lm;
-          pos++;
+      poly* add=(poly*) omalloc((pair_top+2)*sizeof(poly));
+      int piter;
+      int pos=0;
+      for(piter=0;piter<=pair_top;piter++)
+      {
+        sorted_pair_node* s=apairs[piter];
+        if (s->i<0)
+	{
+            //delayed element
+            if (s->lcm_of_lm!=NULL)
+	    {
+                add[pos]=s->lcm_of_lm;
+                pos++;
+            }
         }
-      }
-      free_sorted_pair_node(s,r);
-      apairs[piter]=NULL;
-    }
-    pair_top=-1;
-    add[pos]=NULL;
-    pos=0;
-    while(add[pos]!=NULL)
-    {
-      add_to_basis_ideal_quotient(add[pos],this,NULL);
-      pos++;
-    }
-    for(piter=0;piter<=pair_top;piter++)
-    {
-      sorted_pair_node* s=apairs[piter];
-      assume(s->i>=0);
-      free_sorted_pair_node(s,r);
-      apairs[piter]=NULL;
-    }
-    pair_top=-1;
+        free_sorted_pair_node(s,r);
+        apairs[piter]=NULL;
+      }
+      pair_top=-1;
+      add[pos]=NULL;
+      pos=0;
+      while(add[pos]!=NULL)
+      {
+        add_to_basis_ideal_quotient(add[pos],this,NULL);
+        pos++;
+      }
+      for(piter=0;piter<=pair_top;piter++)
+      {
+        sorted_pair_node* s=apairs[piter];
+        assume(s->i>=0);
+        free_sorted_pair_node(s,r);
+        apairs[piter]=NULL;
+      }
+      pair_top=-1;
   }
   id_Delete(&add_later,r);
@@ -3151,4 +3254,6 @@
 //   initsevS(i);
   omFree(c->strat->S_2_R);
+
+
   omFree(c->strat->lenS);
 
@@ -3184,8 +3289,12 @@
     if(!found) pDelete(&c->strat->S[i]);
   }
-//   for(i=0;i<c->n;i++){
-//     if (c->rep[i]!=i){
-// //       for(j=0;j<=c->strat->sl;j++){
-// //   if(c->strat->S[j]==c->S->m[i]){
+//   for(i=0;i<c->n;i++)
+//   {
+//     if (c->rep[i]!=i)
+//     {
+// //       for(j=0;j<=c->strat->sl;j++)
+// {
+// //   if(c->strat->S[j]==c->S->m[i])
+// {
 // //     c->strat->S[j]=NULL;
 // //     break;
@@ -3199,33 +3308,31 @@
   if (completed)
   {
-    for(i=0;i<c->n;i++)
-    {
-      assume(c->S->m[i]!=NULL);
-      if (p_GetComp(c->S->m[i],currRing)>this->syz_comp) continue;
-      for(j=0;j<c->n;j++)
-      {
-        if((c->S->m[j]==NULL)||(i==j))
-          continue;
-        assume(p_LmShortDivisibleBy(c->S->m[j],c->short_Exps[j],
+  for(i=0;i<c->n;i++)
+  {
+    assume(c->S->m[i]!=NULL);
+    if (p_GetComp(c->S->m[i],currRing)>this->syz_comp) continue;
+    for(j=0;j<c->n;j++)
+    {
+      if((c->S->m[j]==NULL)||(i==j))
+        continue;
+      assume(p_LmShortDivisibleBy(c->S->m[j],c->short_Exps[j],
              c->S->m[i],~c->short_Exps[i],
              c->r)==p_LmDivisibleBy(c->S->m[j],
              c->S->m[i],
              c->r));
-        if (p_LmShortDivisibleBy(c->S->m[j],c->short_Exps[j],
+      if (p_LmShortDivisibleBy(c->S->m[j],c->short_Exps[j],
           c->S->m[i],~c->short_Exps[i],
           c->r))
-        {
-          pDelete(&c->S->m[i]);
-          break;
-        }
-      }
-    }
+      {
+        pDelete(&c->S->m[i]);
+        break;
+      }
+    }
+  }
   }
   omfree(c->short_Exps);
 
   ideal I=c->S;
-
   IDELEMS(I)=c->n;
-
   idSkipZeroes(I);
   for(i=0;i<=c->strat->sl;i++)
@@ -3238,53 +3345,51 @@
 ideal t_rep_gb(ring r,ideal arg_I, int syz_comp, BOOLEAN F4_mode)
 {
-  assume(r==currRing);
-  ring orig_ring=r;
-  int pos;
-  ring new_ring=rAssure_TDeg(orig_ring,1,rVar(orig_ring),pos);
-
-  ideal s_h;
-  if (orig_ring != new_ring)
-  {
-    rChangeCurrRing(new_ring);
-    s_h=idrCopyR_NoSort(arg_I,orig_ring);
-    idTest(s_h);
-    /*int i;
-
-    for(i=0;i<IDELEMS(s_h);i++)
-    {
-      poly p=s_h->m[i];
-      while(p)
-      {
+    assume(r==currRing);
+    ring orig_ring=r;
+    int pos;
+    ring new_ring=rAssure_TDeg(orig_ring,1,rVar(orig_ring),pos);
+    ideal s_h;
+    if (orig_ring != new_ring)
+    {
+        rChangeCurrRing(new_ring);
+        s_h=idrCopyR_NoSort(arg_I,orig_ring);
+        idTest(s_h);
+        /*int i;
+        for(i=0;i<IDELEMS(s_h);i++)
+	{
+            poly p=s_h->m[i];
+            while(p)
+	    {
                 p_Setm(p,new_ring);
                 pIter(p);
-      }
-    }
-    */
-  }
-  else
-  {
-    s_h = id_Copy(arg_I,orig_ring);
-  }
-
-  ideal s_result=do_t_rep_gb(new_ring,s_h,syz_comp,F4_mode,pos);
-  ideal result;
-  if(orig_ring != new_ring)
-  {
-    idTest(s_result);
-    rChangeCurrRing(orig_ring);
-    result = idrMoveR_NoSort(s_result, new_ring);
-
+            }
+        }*/
+    }
+    else
+    {
+        s_h = id_Copy(arg_I,orig_ring);
+    }
+
+    ideal s_result=do_t_rep_gb(new_ring,s_h,syz_comp,F4_mode,pos);
+    ideal result;
+    if(orig_ring != new_ring)
+    {
+        idTest(s_result);
+        rChangeCurrRing(orig_ring);
+        result = idrMoveR_NoSort(s_result, new_ring);
+
+        idTest(result);
+        //rChangeCurrRing(new_ring);
+        rKill(new_ring);
+        //rChangeCurrRing(orig_ring);
+    }
+    else
+        result=s_result;
     idTest(result);
-    //rChangeCurrRing(new_ring);
-    rKill(new_ring);
-    //rChangeCurrRing(orig_ring);
-  }
-  else
-    result=s_result;
-  idTest(result);
-  return result;
-}
-
-ideal do_t_rep_gb(ring r,ideal arg_I, int syz_comp, BOOLEAN F4_mode,int deg_pos){
+    return result;
+}
+
+ideal do_t_rep_gb(ring r,ideal arg_I, int syz_comp, BOOLEAN F4_mode,int deg_pos)
+{
   //  Print("QlogSize(0) %d, QlogSize(1) %d,QlogSize(-2) %d, QlogSize(5) %d\n", QlogSize(nlInit(0)),QlogSize(nlInit(1)),QlogSize(nlInit(-2)),QlogSize(nlInit(5)));
 
@@ -3336,4 +3441,5 @@
   return(I);
 }
+
 void now_t_rep(const int & arg_i, const int & arg_j, slimgb_alg* c)
 {
@@ -3393,4 +3499,5 @@
   {
     //enter tail
+
     if (c->S->m[i]==NULL) continue;
     poly tail=c->S->m[i]->next;
@@ -3444,12 +3551,11 @@
       if (c->strat->lenSw)
         c->strat->lenSw[old_pos]=q;
-
       if (new_pos<old_pos)
         move_forward_in_S(old_pos,new_pos,c->strat);
-
       length_one_crit(c,i,c->lengths[i]);
     }
   }
 }
+
 static sorted_pair_node* pop_pair(slimgb_alg* c)
 {
@@ -3459,4 +3565,5 @@
   else return (c->apairs[c->pair_top--]);
 }
+
 void slimgb_alg::cleanDegs(int lower, int upper)
 {
@@ -3474,52 +3581,52 @@
       if (T_deg[i]==deg)
       {
-        poly h;
-        h=S->m[i];
-        h=redNFTail(h,strat->sl,strat,lengths[i]);
-        if (!rField_is_Zp(r))
-        {
-          p_Cleardenom(h,r);
-          //p_Content(h,r);
-        }
-        else pNorm(h);
+          poly h;
+          h=S->m[i];
+          h=redNFTail(h,strat->sl,strat,lengths[i]);
+          if (!rField_is_Zp(r))
+          {
+            p_Cleardenom(h,r);
+            //p_Content(h,r);
+          }
+          else pNorm(h);
           //TODO:GCD of TERMS
-        poly got=::gcd_of_terms(h,r);
-        p_Delete(&gcd_of_terms[i],r);
-        gcd_of_terms[i]=got;
-        int len=pLength(h);
-        wlen_type wlen=pQuality(h,this,len);
-        if (weighted_lengths)
-          weighted_lengths[i]=wlen;
-        lengths[i]=len;
-        assume(h==S->m[i]);
-        int j;
-        for(j=0;j<=strat->sl;j++)
-        {
-          if (h==strat->S[j])
-          {
-            int new_pos=simple_posInS(strat, h,len, wlen);
-            if (strat->lenS)
-            {
-              strat->lenS[j]=len;
+          poly got=::gcd_of_terms(h,r);
+          p_Delete(&gcd_of_terms[i],r);
+          gcd_of_terms[i]=got;
+          int len=pLength(h);
+          wlen_type wlen=pQuality(h,this,len);
+          if (weighted_lengths)
+            weighted_lengths[i]=wlen;
+          lengths[i]=len;
+          assume(h==S->m[i]);
+          int j;
+          for(j=0;j<=strat->sl;j++)
+	  {
+            if (h==strat->S[j])
+	    {
+              int new_pos=simple_posInS(strat, h,len, wlen);
+              if (strat->lenS)
+	      {
+                strat->lenS[j]=len;
+              }
+              if (strat->lenSw)
+	      {
+                strat->lenSw[j]=wlen;
+              }
+              if (new_pos<j)
+	      {
+                move_forward_in_S(j,new_pos,strat);
+              }
+	      else
+	      {
+                if (new_pos>j)
+                 new_pos=new_pos-1;//is identical with one element
+                if (new_pos>j)
+                  move_backward_in_S(j,new_pos,strat);
+              }
+              break;
             }
-            if (strat->lenSw)
-            {
-              strat->lenSw[j]=wlen;
-            }
-            if (new_pos<j)
-            {
-              move_forward_in_S(j,new_pos,strat);
-            }
-            else
-            {
-              if (new_pos>j)
-                new_pos=new_pos-1;//is identical with one element
-              if (new_pos>j)
-                move_backward_in_S(j,new_pos,strat);
-            }
-            break;
           }
         }
-      }
     }
   }
@@ -3531,5 +3638,5 @@
       {
         if (T_deg[i]+T_deg[j]<=upper)
-        {
+	{
           now_t_rep(i,j,this);
         }
@@ -3540,4 +3647,5 @@
   //TODO mark pairs
 }
+
 sorted_pair_node* top_pair(slimgb_alg* c)
 {
@@ -3556,7 +3664,9 @@
     }
   }
+
   if(c->pair_top<0) return NULL;
   else return (c->apairs[c->pair_top]);
 }
+
 sorted_pair_node* quick_pop_pair(slimgb_alg* c)
 {
@@ -3575,4 +3685,5 @@
   }
 }
+
 void clean_top_of_pair_list(slimgb_alg* c)
 {
@@ -3583,4 +3694,5 @@
   }
 }
+
 static BOOLEAN state_is(calc_state state, const int & arg_i, const  int & arg_j, slimgb_alg* c)
 {
@@ -3606,4 +3718,5 @@
   omfree(s);
 }
+
 static BOOLEAN pair_better(sorted_pair_node* a,sorted_pair_node* b, slimgb_alg* c)
 {
@@ -3632,14 +3745,14 @@
   if (a->deg>b->deg) return 1;
 
-  int comp=pLmCmp(a->lcm_of_lm, b->lcm_of_lm);
+ int comp=pLmCmp(a->lcm_of_lm, b->lcm_of_lm);
 
   if (comp==1) return 1;
   if (-1==comp) return -1;
-  if (a->expected_length<b->expected_length) return -1;
+   if (a->expected_length<b->expected_length) return -1;
   if (a->expected_length>b->expected_length) return 1;
   if (a->i+a->j<b->i+b->j) return -1;
-  if (a->i+a->j>b->i+b->j) return 1;
+   if (a->i+a->j>b->i+b->j) return 1;
   if (a->i<b->i) return -1;
-  if (a->i>b->i) return 1;
+   if (a->i>b->i) return 1;
   return 0;
 }
@@ -3654,9 +3767,10 @@
   for (i=pVariables; i; i--)
   {
-    pSetExp(m,i, pGetExp(p,i));
-    if (max_g_0==0)
-      if (pGetExp(m,i)>0)
-        max_g_0=i;
-  }
+      pSetExp(m,i, pGetExp(p,i));
+      if (max_g_0==0)
+  if (pGetExp(m,i)>0)
+    max_g_0=i;
+  }
+
   t=p->next;
   while (t!=NULL)
@@ -3667,9 +3781,9 @@
       pSetExp(m,i, si_min(pGetExp(t,i),pGetExp(m,i)));
       if (max_g_0==i)
-        if (pGetExp(m,i)==0)
-          max_g_0=0;
+  if (pGetExp(m,i)==0)
+    max_g_0=0;
       if ((max_g_0==0) && (pGetExp(m,i)>0))
       {
-        max_g_0=i;
+  max_g_0=i;
       }
     }
@@ -3682,6 +3796,8 @@
   return NULL;
 }
+
 static inline BOOLEAN pHasNotCFExtended(poly p1, poly p2, poly m)
 {
+
   if (pGetComp(p1) > 0 || pGetComp(p2) > 0)
     return FALSE;
@@ -3695,5 +3811,4 @@
 }
 
-
 //for impl reasons may return false if the the normal product criterion matches
 static inline BOOLEAN extended_product_criterion(poly p1, poly gcd1, poly p2, poly gcd2, slimgb_alg* c)
@@ -3702,14 +3817,15 @@
     return FALSE;
   if(gcd1==NULL) return FALSE;
-  if(gcd2==NULL) return FALSE;
-  gcd1->next=gcd2; //may ordered incorrect
-  poly m=gcd_of_terms(gcd1,c->r);
-  gcd1->next=NULL;
-  if (m==NULL) return FALSE;
-
-  BOOLEAN erg=pHasNotCFExtended(p1,p2,m);
-  pDelete(&m);
-  return erg;
-}
+        if(gcd2==NULL) return FALSE;
+        gcd1->next=gcd2; //may ordered incorrect
+        poly m=gcd_of_terms(gcd1,c->r);
+        gcd1->next=NULL;
+        if (m==NULL) return FALSE;
+
+        BOOLEAN erg=pHasNotCFExtended(p1,p2,m);
+        pDelete(&m);
+        return erg;
+}
+
 static poly kBucketGcd(kBucket* b, ring r)
 {
@@ -3724,24 +3840,24 @@
       if (!initialized)
       {
-        m=gcd_of_terms(b->buckets[i],r);
-        initialized=TRUE;
-        if (m==NULL) return NULL;
+  m=gcd_of_terms(b->buckets[i],r);
+  initialized=TRUE;
+  if (m==NULL) return NULL;
       }
       else
-      {
-        n=gcd_of_terms(b->buckets[i],r);
-        if (n==NULL)
-        {
-          pDelete(&m);
-          return NULL;
-        }
-        n->next=m;
-        poly t=gcd_of_terms(n,r);
-        n->next=NULL;
-        pDelete(&m);
-        pDelete(&n);
-        m=t;
-        if (m==NULL) return NULL;
-      }
+  {
+    n=gcd_of_terms(b->buckets[i],r);
+    if (n==NULL) {
+      pDelete(&m);
+      return NULL;
+    }
+    n->next=m;
+    poly t=gcd_of_terms(n,r);
+    n->next=NULL;
+    pDelete(&m);
+    pDelete(&n);
+    m=t;
+    if (m==NULL) return NULL;
+
+  }
     }
   }
@@ -3754,4 +3870,5 @@
   return c->strat->lenS[pos];
 }
+
 #ifdef HAVE_PLURAL
 static inline wlen_type quality_of_pos_in_strat_S_mult_high(int pos, poly high, slimgb_alg* c)
@@ -3780,248 +3897,255 @@
       int best=erg.to_reduce_u+1;
 /*
-      for (i=erg.to_reduce_u;i>=erg.to_reduce_l;i--){
+      for (i=erg.to_reduce_u;i>=erg.to_reduce_l;i--)
+      {
   int qc=los[i].guess_quality(c);
-  if (qc<quality_a){
+  if (qc<quality_a)
+  {
     best=i;
     quality_a=qc;
   }
       }
-      if(best!=erg.to_reduce_u+1){
-*/
+      if(best!=erg.to_reduce_u+1)
+      {*/
       wlen_type qc;
       best=find_best(los,erg.to_reduce_l,erg.to_reduce_u,qc,c);
       if(qc<quality_a)
       {
-        los[best].flatten();
-        int b_pos=kBucketCanonicalize(los[best].bucket);
-        los[best].p=los[best].bucket->buckets[b_pos];
-        qc=pQuality(los[best].bucket->buckets[b_pos],c);
-        if(qc<quality_a)
-        {
-          red_object h=los[erg.to_reduce_u];
-          los[erg.to_reduce_u]=los[best];
-          los[best]=h;
-          swap_roles=TRUE;
-        }
-        else
-          swap_roles=FALSE;
+  los[best].flatten();
+  int b_pos=kBucketCanonicalize(los[best].bucket);
+  los[best].p=los[best].bucket->buckets[b_pos];
+  qc=pQuality(los[best].bucket->buckets[b_pos],c);
+  if(qc<quality_a)
+  {
+    red_object h=los[erg.to_reduce_u];
+    los[erg.to_reduce_u]=los[best];
+    los[best]=h;
+    swap_roles=TRUE;
+  }
+  else
+    swap_roles=FALSE;
       }
       else
       {
-        swap_roles=FALSE;
-      }
+  swap_roles=FALSE;
+      }
+    }
+      else
+    {
+      if (erg.to_reduce_u>erg.to_reduce_l)
+      {
+  int i;
+  wlen_type quality_a=quality_of_pos_in_strat_S(erg.reduce_by,c);
+  #ifdef HAVE_PLURAL
+  if ((c->nc) && (!(rIsSCA(c->r))))
+    quality_a=quality_of_pos_in_strat_S_mult_high(erg.reduce_by, los[erg.to_reduce_u].p, c);
+  #endif
+  int best=erg.to_reduce_u+1;
+  wlen_type qc;
+  best=find_best(los,erg.to_reduce_l,erg.to_reduce_u,qc,c);
+  assume(qc==los[best].guess_quality(c));
+  if(qc<quality_a)
+  {
+    los[best].flatten();
+    int b_pos=kBucketCanonicalize(los[best].bucket);
+    los[best].p=los[best].bucket->buckets[b_pos];
+    qc==pQuality(los[best].bucket->buckets[b_pos],c);
+    //(best!=erg.to_reduce_u+1)
+    if(qc<quality_a)
+    {
+    red_object h=los[erg.to_reduce_u];
+    los[erg.to_reduce_u]=los[best];
+    los[best]=h;
+    erg.reduce_by=erg.to_reduce_u;
+    erg.fromS=FALSE;
+    erg.to_reduce_u--;
+    }
+  }
+      }
+      else
+      {
+  assume(erg.to_reduce_u==erg.to_reduce_l);
+  wlen_type quality_a=
+        quality_of_pos_in_strat_S(erg.reduce_by,c);
+  wlen_type qc=los[erg.to_reduce_u].guess_quality(c);
+  if (qc<0) PrintS("Wrong wlen_type");
+  if(qc<quality_a)
+  {
+    int best=erg.to_reduce_u;
+    los[best].flatten();
+    int b_pos=kBucketCanonicalize(los[best].bucket);
+    los[best].p=los[best].bucket->buckets[b_pos];
+    qc=pQuality(los[best].bucket->buckets[b_pos],c);
+    assume(qc>=0);
+    if(qc<quality_a)
+    {
+      BOOLEAN exp=FALSE;
+      if(qc<=2)
+      {
+         //Print("\n qc is %lld \n",qc);
+         exp=TRUE;
+      }
+      else
+      {
+         if (qc<quality_a/2)
+          exp=TRUE;
+         else
+       if(erg.reduce_by<c->n/4)
+          exp=TRUE;
+      }
+      if (exp)
+      {
+        poly clear_into;
+        los[erg.to_reduce_u].flatten();
+        kBucketClear(los[erg.to_reduce_u].bucket,&clear_into,&erg.expand_length);
+        erg.expand=pCopy(clear_into);
+        kBucketInit(los[erg.to_reduce_u].bucket,clear_into,erg.expand_length);
+        if (TEST_OPT_PROT)
+    PrintS("e");
+      }
+    }
+  }
+      }
+
+      swap_roles=FALSE;
+      return;
+      }
+  }
+  else
+  {
+    if(erg.reduce_by>erg.to_reduce_u)
+    {
+      //then lm(rb)>= lm(tru) so =
+      assume(erg.reduce_by==erg.to_reduce_u+1);
+      int best=erg.reduce_by;
+      wlen_type quality_a=los[erg.reduce_by].guess_quality(c);
+      wlen_type qc;
+      best=find_best(los,erg.to_reduce_l,erg.to_reduce_u,qc,c);
+
+      int i;
+      if(qc<quality_a)
+      {
+    red_object h=los[erg.reduce_by];
+    los[erg.reduce_by]=los[best];
+    los[best]=h;
+  }
+  swap_roles=FALSE;
+  return;
     }
     else
     {
-      if (erg.to_reduce_u>erg.to_reduce_l)
-      {
-        int i;
-        wlen_type quality_a=quality_of_pos_in_strat_S(erg.reduce_by,c);
-#ifdef HAVE_PLURAL
-        if ((c->nc) && (!(rIsSCA(c->r))))
-         quality_a=quality_of_pos_in_strat_S_mult_high(erg.reduce_by, los[erg.to_reduce_u].p, c);
+      assume(!pLmEqual(los[erg.reduce_by].p,los[erg.to_reduce_l].p));
+      assume(erg.to_reduce_u==erg.to_reduce_l);
+      //further assume, that reduce_by is the above all other polys
+      //with same leading term
+      int il=erg.reduce_by;
+      wlen_type quality_a =los[erg.reduce_by].guess_quality(c);
+      wlen_type qc;
+      while((il>0) && pLmEqual(los[il-1].p,los[il].p))
+      {
+  il--;
+  qc=los[il].guess_quality(c);
+  if (qc<quality_a)
+  {
+    quality_a=qc;
+    erg.reduce_by=il;
+  }
+      }
+      swap_roles=FALSE;
+    }
+  }
+  if(swap_roles)
+  {
+    if (TEST_OPT_PROT)
+      PrintS("b");
+    poly clear_into;
+    int dummy_len;
+    int new_length;
+    int bp=erg.to_reduce_u;//bucket_positon
+    //kBucketClear(los[bp].bucket,&clear_into,&new_length);
+    new_length=los[bp].clear_to_poly();
+    clear_into=los[bp].p;
+    poly p=c->strat->S[erg.reduce_by];
+    int j=erg.reduce_by;
+    int old_length=c->strat->lenS[j];// in view of S
+    los[bp].p=p;
+    if (c->eliminationProblem)
+    {
+        los[bp].sugar=c->pTotaldegree_full(p);
+    }
+    kBucketInit(los[bp].bucket,p,old_length);
+    wlen_type qal=pQuality(clear_into,c,new_length);
+    int pos_in_c=-1;
+    int z;
+    int new_pos;
+    new_pos=simple_posInS(c->strat,clear_into,new_length, qal);
+    assume(new_pos<=j);
+    for (z=c->n;z;z--)
+    {
+      if(p==c->S->m[z-1])
+      {
+  pos_in_c=z-1;
+  break;
+      }
+    }
+
+    int tdeg_full=-1;
+    int tdeg=-1;
+    if(pos_in_c>=0)
+    {
+      #ifdef TGB_RESORT_PAIRS
+      c->used_b=TRUE;
+      c->replaced[pos_in_c]=TRUE;
+      #endif
+      tdeg=c->T_deg[pos_in_c];
+      c->S->m[pos_in_c]=clear_into;
+      c->lengths[pos_in_c]=new_length;
+      c->weighted_lengths[pos_in_c]=qal;
+      if (c->gcd_of_terms[pos_in_c]==NULL)
+        c->gcd_of_terms[pos_in_c]=gcd_of_terms(clear_into,c->r);
+      if (c->T_deg_full)
+        tdeg_full=c->T_deg_full[pos_in_c]=c->pTotaldegree_full(clear_into);
+      else tdeg_full=tdeg;
+      c_S_element_changed_hook(pos_in_c,c);
+    }
+    else
+    {
+      if (c->eliminationProblem)
+      {
+        tdeg_full=c->pTotaldegree_full(clear_into);
+        tdeg=c->pTotaldegree(clear_into);
+      }
+    }
+    c->strat->S[j]=clear_into;
+    c->strat->lenS[j]=new_length;
+
+    assume(pLength(clear_into)==new_length);
+    if(c->strat->lenSw!=NULL)
+      c->strat->lenSw[j]=qal;
+    if (!rField_is_Zp(c->r))
+    {
+      p_Cleardenom(clear_into,c->r);//should be unnecessary
+      //p_Content(clear_into, c->r);
+    }
+    else
+      pNorm(clear_into);
+#ifdef FIND_DETERMINISTIC
+    erg.reduce_by=j;
+    //resort later see diploma thesis, find_in_S must be deterministic
+    //during multireduction if spolys are only in the span of the
+    //input polys
+#else
+    if (new_pos<j)
+    {
+      if (c->strat->honey) c->strat->ecartS[j]=tdeg_full-tdeg;
+      move_forward_in_S(j,new_pos,c->strat);
+      erg.reduce_by=new_pos;
+    }
 #endif
-        int best=erg.to_reduce_u+1;
-        wlen_type qc;
-        best=find_best(los,erg.to_reduce_l,erg.to_reduce_u,qc,c);
-        assume(qc==los[best].guess_quality(c));
-        if(qc<quality_a)
-        {
-          los[best].flatten();
-          int b_pos=kBucketCanonicalize(los[best].bucket);
-          los[best].p=los[best].bucket->buckets[b_pos];
-          qc==pQuality(los[best].bucket->buckets[b_pos],c);
-          //(best!=erg.to_reduce_u+1)
-          if(qc<quality_a)
-          {
-            red_object h=los[erg.to_reduce_u];
-            los[erg.to_reduce_u]=los[best];
-            los[best]=h;
-            erg.reduce_by=erg.to_reduce_u;
-            erg.fromS=FALSE;
-            erg.to_reduce_u--;
-          }
-        }
-      }
-      else
-      {
-        assume(erg.to_reduce_u==erg.to_reduce_l);
-        wlen_type quality_a=
-          quality_of_pos_in_strat_S(erg.reduce_by,c);
-         wlen_type qc=los[erg.to_reduce_u].guess_quality(c);
-         if (qc<0) PrintS("Wrong wlen_type");
-         if(qc<quality_a)
-         {
-           int best=erg.to_reduce_u;
-           los[best].flatten();
-           int b_pos=kBucketCanonicalize(los[best].bucket);
-           los[best].p=los[best].bucket->buckets[b_pos];
-           qc=pQuality(los[best].bucket->buckets[b_pos],c);
-           assume(qc>=0);
-           if(qc<quality_a)
-           {
-             BOOLEAN exp=FALSE;
-             if(qc<=2)
-             {
-               //Print("\n qc is %lld \n",qc);
-               exp=TRUE;
-             }
-             else
-             {
-               if (qc<quality_a/2)
-                 exp=TRUE;
-               else
-                 if(erg.reduce_by<c->n/4)
-                   exp=TRUE;
-             }
-             if (exp)
-             {
-               poly clear_into;
-               los[erg.to_reduce_u].flatten();
-               kBucketClear(los[erg.to_reduce_u].bucket,&clear_into,&erg.expand_length);
-               erg.expand=pCopy(clear_into);
-               kBucketInit(los[erg.to_reduce_u].bucket,clear_into,erg.expand_length);
-               if (TEST_OPT_PROT) PrintS("e");
-             }
-           }
-         }
-       }
-       swap_roles=FALSE;
-       return;
-     }
-   }
-   else
-   {
-     if(erg.reduce_by>erg.to_reduce_u)
-     {
-       //then lm(rb)>= lm(tru) so =
-       assume(erg.reduce_by==erg.to_reduce_u+1);
-       int best=erg.reduce_by;
-       wlen_type quality_a=los[erg.reduce_by].guess_quality(c);
-       wlen_type qc;
-       best=find_best(los,erg.to_reduce_l,erg.to_reduce_u,qc,c);
-
-       int i;
-       if(qc<quality_a)
-       {
-         red_object h=los[erg.reduce_by];
-         los[erg.reduce_by]=los[best];
-         los[best]=h;
-       }
-       swap_roles=FALSE;
-       return;
-     }
-     else
-     {
-       assume(!pLmEqual(los[erg.reduce_by].p,los[erg.to_reduce_l].p));
-       assume(erg.to_reduce_u==erg.to_reduce_l);
-       //further assume, that reduce_by is the above all other polys
-       //with same leading term
-       int il=erg.reduce_by;
-       wlen_type quality_a =los[erg.reduce_by].guess_quality(c);
-       wlen_type qc;
-       while((il>0) && pLmEqual(los[il-1].p,los[il].p))
-       {
-         il--;
-         qc=los[il].guess_quality(c);
-         if (qc<quality_a)
-         {
-           quality_a=qc;
-           erg.reduce_by=il;
-         }
-       }
-       swap_roles=FALSE;
-     }
-   }
-   if(swap_roles)
-   {
-     if (TEST_OPT_PROT) PrintS("b");
-     poly clear_into;
-     int dummy_len;
-     int new_length;
-     int bp=erg.to_reduce_u;//bucket_positon
-     //kBucketClear(los[bp].bucket,&clear_into,&new_length);
-     new_length=los[bp].clear_to_poly();
-     clear_into=los[bp].p;
-     poly p=c->strat->S[erg.reduce_by];
-     int j=erg.reduce_by;
-     int old_length=c->strat->lenS[j];// in view of S
-     los[bp].p=p;
-     if (c->eliminationProblem)
-     {
-        los[bp].sugar=c->pTotaldegree_full(p);
-     }
-     kBucketInit(los[bp].bucket,p,old_length);
-     wlen_type qal=pQuality(clear_into,c,new_length);
-     int pos_in_c=-1;
-     int z;
-     int new_pos;
-     new_pos=simple_posInS(c->strat,clear_into,new_length, qal);
-     assume(new_pos<=j);
-     for (z=c->n;z;z--)
-     {
-       if(p==c->S->m[z-1])
-       {
-         pos_in_c=z-1;
-         break;
-       }
-     }
-
-     int tdeg_full=-1;
-     int tdeg=-1;
-     if(pos_in_c>=0)
-     {
-       #ifdef TGB_RESORT_PAIRS
-       c->used_b=TRUE;
-       c->replaced[pos_in_c]=TRUE;
-       #endif
-       tdeg=c->T_deg[pos_in_c];
-       c->S->m[pos_in_c]=clear_into;
-       c->lengths[pos_in_c]=new_length;
-       c->weighted_lengths[pos_in_c]=qal;
-       if (c->gcd_of_terms[pos_in_c]==NULL)
-         c->gcd_of_terms[pos_in_c]=gcd_of_terms(clear_into,c->r);
-       if (c->T_deg_full)
-         tdeg_full=c->T_deg_full[pos_in_c]=c->pTotaldegree_full(clear_into);
-       else tdeg_full=tdeg;
-       c_S_element_changed_hook(pos_in_c,c);
-     }
-     else
-     {
-       if (c->eliminationProblem)
-       {
-         tdeg_full=c->pTotaldegree_full(clear_into);
-         tdeg=c->pTotaldegree(clear_into);
-       }
-     }
-     c->strat->S[j]=clear_into;
-     c->strat->lenS[j]=new_length;
-
-     assume(pLength(clear_into)==new_length);
-     if(c->strat->lenSw!=NULL)
-       c->strat->lenSw[j]=qal;
-     if (!rField_is_Zp(c->r))
-     {
-       p_Cleardenom(clear_into,c->r);//should be unnecessary
-       //p_Content(clear_into, c->r);
-     }
-     else
-       pNorm(clear_into);
-#ifdef FIND_DETERMINISTIC
-     erg.reduce_by=j;
-     //resort later see diploma thesis, find_in_S must be deterministic
-     //during multireduction if spolys are only in the span of the
-     //input polys
-#else
-     if (new_pos<j)
-     {
-       if (c->strat->honey) c->strat->ecartS[j]=tdeg_full-tdeg;
-       move_forward_in_S(j,new_pos,c->strat);
-       erg.reduce_by=new_pos;
-     }
-#endif
-   }
-}
-static int fwbw(red_object* los, int i){
+  }
+}
+
+static int fwbw(red_object* los, int i)
+{
    int i2=i;
    int step=1;
@@ -4047,14 +4171,12 @@
    if ((!incr) &&(step==1)) break;
        }
-
-
      }
      else
      {
-
        step=si_min(i-i2,step);
        if (step==0) break;
        i2+=step;
-       if(pLmEqual(los[i].p,los[i2].p)){
+       if(pLmEqual(los[i].p,los[i2].p))
+       {
    if(step==1) break;
    else
@@ -4063,5 +4185,4 @@
    }
        }
-
      }
      if (incr)
@@ -4073,18 +4194,20 @@
        else
    step/=2;
-
      }
    }
    return i2;
 }
-static void canonicalize_region(red_object* los, int l, int u,slimgb_alg* c){
+
+static void canonicalize_region(red_object* los, int l, int u,slimgb_alg* c)
+{
     assume(l<=u+1);
     int i;
-    for(i=l;i<=u;i++){
+    for(i=l;i<=u;i++)
+    {
         kBucketCanonicalize(los[i].bucket);
     }
-
-}
-static void multi_reduction_find(red_object* los, int losl,slimgb_alg* c,int startf,find_erg & erg){
+}
+static void multi_reduction_find(red_object* los, int losl,slimgb_alg* c,int startf,find_erg & erg)
+{
   kStrategy strat=c->strat;
 
@@ -4094,11 +4217,12 @@
 
   int j;
-  while(i>=0){
+  while(i>=0)
+  {
     assume((i==losl-1)||(pLmCmp(los[i].p,los[i+1].p)<=0));
     assume(is_valid_ro(los[i]));
     assume((!(c->eliminationProblem))||(los[i].sugar>=c->pTotaldegree(los[i].p)));
     j=kFindDivisibleByInS_easy(strat,los[i]);
-    if(j>=0){
-
+    if(j>=0)
+    {
       erg.to_reduce_u=i;
       erg.reduce_by=j;
@@ -4109,5 +4233,4 @@
       assume(i>=i2);
 
-
       erg.to_reduce_l=i2;
       assume((i==losl-1)||(pLmCmp(los[i].p,los[i+1].p)==-1));
@@ -4115,6 +4238,6 @@
       return;
     }
-    if (j<0){
-
+    if (j<0)
+    {
       //not reduceable, try to use this for reducing higher terms
       int i2=fwbw(los,i);
@@ -4122,7 +4245,6 @@
       assume((i2==0)||(!pLmEqual(los[i2].p,los[i2-1].p)));
       assume(i>=i2);
-      if(i2!=i){
-
-
+      if(i2!=i)
+      {
   erg.to_reduce_u=i-1;
   erg.to_reduce_l=i2;
@@ -4133,5 +4255,4 @@
   return;
       }
-
       i--;
     }
@@ -4143,10 +4264,9 @@
  //  nicht reduzierbare eintraege in ergebnisliste schreiben
 //   nullen loeschen
-//   while(finde_groessten leitterm reduzierbar(c,erg)){
+//   while(finde_groessten leitterm reduzierbar(c,erg))
+//   {
 
 static int multi_reduction_clear_zeroes(red_object* los, int  losl, int l, int u)
 {
-
-
   int deleted=0;
   int  i=l;
@@ -4154,6 +4274,6 @@
   while(i<=u)
   {
-
-    if(los[i].p==NULL){
+    if(los[i].p==NULL)
+    {
       kBucketDestroy(&los[i].bucket);
 //      delete los[i];//here we assume los are constructed with new
@@ -4171,8 +4291,8 @@
       memmove(los+(int)(last+1-deleted),los+last+1,sizeof(red_object)*(losl-1-last));
   return deleted;
-
-}
-int search_red_object_pos(red_object* a, int top, red_object* key ){
-
+}
+
+int search_red_object_pos(red_object* a, int top, red_object* key )
+{
     int an = 0;
     int en= top;
@@ -4195,6 +4315,6 @@
         an=i;
     }
-
-}
+}
+
 static void sort_region_down(red_object* los, int l, int u, slimgb_alg* c)
 {
@@ -4205,19 +4325,22 @@
   int bound=0;
   BOOLEAN at_end=FALSE;
-  for(i=l;i<=u;i++){
-    if (!(at_end)){
+  for(i=l;i<=u;i++)
+  {
+    if (!(at_end))
+    {
       bound=new_indices[i-l]=bound+search_red_object_pos(los+bound,l-bound-1,los+i);
       if (bound==l) at_end=TRUE;
     }
-    else{
+    else
+    {
       new_indices[i-l]=l;
     }
   }
   red_object* los_region=(red_object*) omalloc(sizeof(red_object)*(u-l+1));
-  for (int i=0;i<r_size;i++){
+  for (int i=0;i<r_size;i++)
+  {
     new_indices[i]+=i;
     los_region[i]=los[l+i];
     assume((i==0)||(new_indices[i]>new_indices[i-1]));
-
   }
 
@@ -4225,10 +4348,14 @@
   int j=u;
   int j2=l-1;
-  while(i>=0){
-    if (new_indices[i]==j){
+  while(i>=0)
+  {
+    if (new_indices[i]==j)
+    {
       los[j]=los_region[i];
       i--;
       j--;
-    } else{
+    }
+    else
+    {
       assume(new_indices[i]<j);
       los[j]=los[j2];
@@ -4239,7 +4366,5 @@
   }
   omfree(los_region);
-
   omfree(new_indices);
-
 }
 
@@ -4255,5 +4380,6 @@
   wlen_type max_initial_quality=0;
 
-  for(i=0;i<losl;i++){
+  for(i=0;i<losl;i++)
+  {
     los[i].sev=pGetShortExpVector(los[i].p);
 //SetShortExpVector();
@@ -4269,12 +4395,14 @@
   int curr_pos=losl-1;
 
-
 //  nicht reduzierbare eintrï¿œe in ergebnisliste schreiben
   // nullen loeschen
-  while(curr_pos>=0){
-    if ((c->use_noro_last_block)&&(lies_in_last_dp_block(los[curr_pos].p,c))){
+  while(curr_pos>=0)
+  {
+    if ((c->use_noro_last_block)&&(lies_in_last_dp_block(los[curr_pos].p,c)))
+    {
         int pn_noro=curr_pos+1;
         poly* p_noro=(poly*) omalloc(pn_noro*sizeof(poly));
-        for(i=0;i<pn_noro;i++){
+        for(i=0;i<pn_noro;i++)
+	{
             int dummy_len;
             poly p;
@@ -4283,21 +4411,25 @@
             p_noro[i]=p;
         }
-
-
-        if (npPrimeM<255){
+        if (npPrimeM<255)
+	{
           noro_step<tgb_uint8>(p_noro,pn_noro,c);
-        } else {
-          if (npPrimeM<65000){
+        }
+	else
+	{
+          if (npPrimeM<65000)
+	  {
             noro_step<tgb_uint16>(p_noro,pn_noro,c);
-          } else{
+          }
+	  else
+	  {
             noro_step<tgb_uint32>(p_noro,pn_noro,c);
           }
         }
-        for(i=0;i<pn_noro;i++){
+        for(i=0;i<pn_noro;i++)
+	{
             los[i].p=p_noro[i];
             los[i].sev=pGetShortExpVector(los[i].p);
             //ignore quality
             kBucketInit(los[i].bucket,los[i].p,pLength(los[i].p));
-
         }
         qsort(los,pn_noro,sizeof(red_object),red_object_better_gen);
@@ -4312,12 +4444,8 @@
     if(erg.reduce_by<0) break;
 
-
-
     erg.expand=NULL;
     int d=erg.to_reduce_u-erg.to_reduce_l+1;
 
-
     multi_reduction_lls_trick(los,losl,c,erg);
-
 
     int i;
@@ -4336,12 +4464,13 @@
          //
          assume(los[i].initial_quality>0);
-
                if(los[i].guess_quality(c)
-                  >1.5*delay_factor*max_initial_quality){
+                  >1.5*delay_factor*max_initial_quality)
+		  {
                        if (TEST_OPT_PROT)
                            PrintS("v");
                        los[i].canonicalize();
                        if(los[i].guess_quality(c)
-                           >delay_factor*max_initial_quality){
+                           >delay_factor*max_initial_quality)
+			   {
                                if (TEST_OPT_PROT)
                                    PrintS(".");
@@ -4350,10 +4479,7 @@
                                delay[delay_s]=los[i].p;
                                delay_s++;
-
                                los[i].p=NULL;
-
                       }
                   }
-
             }
      }
@@ -4372,5 +4498,4 @@
     else
     sort_region_down(los, erg.to_reduce_l, erg.to_reduce_u-deleted, c);
-
 
     if(erg.expand)
@@ -4384,5 +4509,6 @@
 #else
       int ecart=0;
-      if (c->eliminationProblem){
+      if (c->eliminationProblem)
+      {
         ecart=c->pTotaldegree_full(erg.expand)-c->pTotaldegree(erg.expand);
       }
@@ -4390,7 +4516,5 @@
 #endif
     }
-
-  }
-
+  }
 
   //sorted_pair_node** pairs=(sorted_pair_node**)
@@ -4398,6 +4522,6 @@
   c->introduceDelayedPairs(delay,delay_s);
   /*
-  for(i=0;i<delay_s;i++){
-
+  for(i=0;i<delay_s;i++)
+  {
       poly p=delay[i];
       //if (rPar(c->r)==0)
@@ -4406,5 +4530,6 @@
       si->i=-1;
       si->j=-1;
-       if (!rField_is_Zp(c->r)){
+       if (!rField_is_Zp(c->r))
+       {
         if (!c->nc)
             p=redTailShort(p, c->strat);
@@ -4414,5 +4539,4 @@
       si->expected_length=pQuality(p,c,pLength(p));
       si->deg=pTotaldegree(p);
-
       si->lcm_of_lm=p;
       pairs[i]=si;
@@ -4425,13 +4549,19 @@
   return;
 }
-void red_object::flatten(){
+
+void red_object::flatten()
+{
   assume(p==kBucketGetLm(bucket));
 }
-void red_object::validate(){
+
+void red_object::validate()
+{
   p=kBucketGetLm(bucket);
   if(p)
     sev=pGetShortExpVector(p);
 }
-int red_object::clear_to_poly(){
+
+int red_object::clear_to_poly()
+{
   flatten();
   int l;
@@ -4440,9 +4570,6 @@
 }
 
-
-
-
-
 void reduction_step::reduce(red_object* r, int l, int u){}
+
 void simple_reducer::do_reduce(red_object & ro)
 {
@@ -4459,6 +4586,6 @@
 }
 
-
-void simple_reducer::reduce(red_object* r, int l, int u){
+void simple_reducer::reduce(red_object* r, int l, int u)
+{
   this->pre_reduce(r,l,u);
   int i;
@@ -4466,6 +4593,6 @@
   int im;
 
-
-  if(c->eliminationProblem){
+  if(c->eliminationProblem)
+  {
     assume(p_LmEqual(r[l].p,r[u].p,c->r));
     /*int lm_deg=pTotaldegree(r[l].p);
@@ -4473,15 +4600,14 @@
   }
 
-  for(i=l;i<=u;i++){
-
-
-
+  for(i=l;i<=u;i++)
+  {
     this->do_reduce(r[i]);
-    if (c->eliminationProblem){
+    if (c->eliminationProblem)
+    {
         r[i].sugar=si_max(r[i].sugar,reducer_deg);
     }
   }
-  for(i=l;i<=u;i++){
-
+  for(i=l;i<=u;i++)
+  {
     kBucketSimpleContent(r[i].bucket);
     r[i].validate();
@@ -4490,6 +4616,9 @@
   }
 }
+
 reduction_step::~reduction_step(){}
-simple_reducer::~simple_reducer(){
+
+simple_reducer::~simple_reducer()
+{
   if(fill_back!=NULL)
   {
@@ -4497,8 +4626,8 @@
   }
   fill_back=NULL;
-
-}
-
-void multi_reduce_step(find_erg & erg, red_object* r, slimgb_alg* c){
+}
+
+void multi_reduce_step(find_erg & erg, red_object* r, slimgb_alg* c)
+{
   static int id=0;
   id++;
@@ -4510,5 +4639,6 @@
   simple_reducer* pointer;
   BOOLEAN work_on_copy=FALSE;
-  if(erg.fromS){
+  if(erg.fromS)
+  {
     red=c->strat->S[rn];
     red_len=c->strat->lenS[rn];
@@ -4539,5 +4669,6 @@
     red_len=pLength(red);
   }
-  if (((TEST_V_MODPSOLVSB)&&(red_len>1))||((c->nc)||(erg.to_reduce_u-erg.to_reduce_l>5))){
+  if (((TEST_V_MODPSOLVSB)&&(red_len>1))||((c->nc)||(erg.to_reduce_u-erg.to_reduce_l>5)))
+  {
     work_on_copy=TRUE;
     // poly m=pOne();
@@ -4555,5 +4686,6 @@
     #endif
       red_cp=ppMult_mm(red,m);
-    if(!erg.fromS){
+    if(!erg.fromS)
+    {
       kBucketInit(r[rn].bucket,red,red_len);
     }
@@ -4572,19 +4704,20 @@
     red_len=pLength(red);
     // pDelete(&m);
-
   }
   int i;
 
-
-
   assume(red_len==pLength(red));
 
   int reducer_deg=0;
-  if (c->eliminationProblem){
+  if (c->eliminationProblem)
+  {
      int lm_deg=c->pTotaldegree(r[erg.to_reduce_l].p);
      int ecart;
-     if (erg.fromS){
+     if (erg.fromS)
+     {
        ecart=c->strat->ecartS[erg.reduce_by];
-     } else {
+     }
+     else
+     {
        ecart=c->pTotaldegree_full(red)-lm_deg;
      }
@@ -4603,13 +4736,10 @@
   if(work_on_copy) pDelete(&pointer->p);
   delete pointer;
-  if (lt_changed){
+  if (lt_changed)
+  {
     assume(!erg.fromS);
     r[erg.reduce_by].sev=sev;
   }
-
-};
-
-
-
+}
 
 void simple_reducer:: pre_reduce(red_object* r, int l, int u){}
