anchor.diff:                    enddo
                   enddo
                 enddo
  +            elseif(CCD .and. factorized)then 
  +               ! Sum over l,d
  +                      in1 = in1 + 0.5d0 *  t2old(d,b,l,j) * X1(l,d,a,i)
  +                     !in1 = in1 + 0.5d0 *  t2old(a,c,i,k)*t2old(d,b,l,j)   * AMO(k,l,c,d)
  +                      in1 = in1 - 0.5d0 *  t2old(d,a,l,j) * X1(l,d,b,i)
  +                     !in1 = in1 - 0.5d0 *  t2old(b,c,i,k)*t2old(d,a,l,j)   * AMO(k,l,c,d)
  +                      in1 = in1 + 0.5d0 *  t2old(d,a,l,i) * X1(l,d,b,j) 
  +                     !in1 = in1 + 0.5d0 *  t2old(b,c,j,k)*t2old(d,a,l,i)   * AMO(k,l,c,d)
  +                      in1 = in1 - 0.5d0 *  t2old(d,b,l,i) * X1(l,d,a,j)
  +                     !in1 = in1 - 0.5d0 *  t2old(a,c,j,k)*t2old(d,b,l,i)   * AMO(k,l,c,d)
  +
  +               ! Sum over k,l
  +                      in1 = in1 + 0.25d0*  t2old(a,b,k,l) * X2(k,l,i,j)
  +                     !in1 = in1 + 0.25d0*  t2old(c,d,i,j)*t2old(a,b,k,l)   * AMO(k,l,c,d)
  +
  +               ! Sum over c
  +                      in1 = in1 - 0.5d0 *  t2old(a,c,i,j) * X3(b,c) 
  +                     !in1 = in1 - 0.5d0 *  t2old(a,c,i,j)*t2old(b,d,k,l)   * AMO(k,l,c,d)
  +                      in1 = in1 + 0.5d0 *  t2old(b,c,i,j) * X3(a,c)
  +                     !in1 = in1 + 0.5d0 *  t2old(b,c,i,j)*t2old(a,d,k,l)   * AMO(k,l,c,d)
  +
  +               ! Sum over k
  +                      in1 = in1 - 0.5d0 *  t2old(a,b,i,k) * X4(k,j)
  +                     !in1 = in1 - 0.5d0 *  t2old(a,b,i,k)*t2old(c,d,j,l)   * AMO(k,l,c,d)
  +                      in1 = in1 + 0.5d0 *  t2old(a,b,j,k) * X4(k,i)
  +                     !in1 = in1 + 0.5d0 *  t2old(a,b,j,k)*t2old(c,d,i,l)   * AMO(k,l,c,d)
  +
               endif
   
   
  
positive.code:     Eold  = Eccd
      t2old  = t2 !R0.5d0*(t2+t2old) ! uses mixing
  
      !T2 equations
  !$OMP PARALLEL PRIVATE(i,j,a,b,k,l,c,d,Dijab,in1)
  !$OMP DO
  
negative.code:               enddo
              enddo
  
              if(CCD .and. .not. factorized)then ! do full CCD
              !Terms that are quadratic in T2
                do c = nOcc+1,nmo
                  do d = nOcc+1,nmo
  