anchor.diff:    integer, allocatable           :: hp(:,:)
   
   
  -  integer                         :: i_state, i, i_I, J, k, k2, k1, kk, ll, degree, degree2, m, l, deg, ni, m2
  +  integer                         :: i_state, i, i_I, J, k, k2, k1, kk, ll, m, l, deg, ni, m2
     integer                         :: n(2)
     integer                         :: p1,p2,h1,h2,s1,s2, blok, I_s, J_s, kn
     logical                         :: ok
  -  double precision                :: phase_iI, phase_Ik, phase_Jl, phase_Ji, phase_al
  +  double precision                :: phase_ia, phase_Ik, phase_Jl, phase_Ji, phase_la, phase_ka, phase_tmp
  +  double precision                :: Hka, Hla, Ska, Sla, tmp
     double precision                :: diI, hIi, hJi, delta_JI, dkI, HkI, ci_inv(N_states), cj_inv(N_states)
     double precision                :: contrib, contrib_s2, wall, iwall
  -  double precision, allocatable   :: dleat(:,:,:), dleat_s2(:,:,:)
  -  integer, dimension(0:2,2,2)     :: exc_iI, exc_Ik, exc_IJ
  +  integer, dimension(0:2,2,2)     :: exc_iI, exc_Ik, exc_IJ, exc
     integer(bit_kind)               :: det_tmp(N_int, 2), det_tmp2(N_int, 2), inac, virt
     integer, external               :: get_index_in_psi_det_sorted_bit, searchDet, detCmp
  -  logical, external               :: is_in_wavefunction, isInCassd, detEq
  +  logical, external               :: is_in_wavefunction
     integer,allocatable :: komon(:)
     logical :: komoned
     !double precision, external :: get_dij
  
positive.code:           
            if(h_cache(J,i) == 0.d0) cycle
            if(h_cache(i_I,i) == 0.d0) cycle
            
            !ok = .false.
            !do i_state=1, N_states
            !  if(lambda_mrcc(i_state, i) /= 0d0) then
            !    ok = .true.
            !    exit
            !  end if
            !end do
            !if(.not. ok) cycle
  !         
            
            komon(0) += 1
            kn = komon(0)
            komon(kn) = i
            
            
  !           call get_excitation(psi_ref(1,1,J),psi_non_ref(1,1,i),exc_IJ,degree2,phase_Ji,N_int)
  !           if(I_i /= J) call get_excitation(psi_ref(1,1,I_i),psi_non_ref(1,1,i),exc_IJ,degree2,phase_Ii,N_int)
  !           if(I_i == J) phase_Ii = phase_Ji
            
            do i_state = 1,N_states
              dkI = h_cache(J,i) * dij(i_I, i, i_state)
              dleat(i_state, kn, 1) = dkI
              dleat(i_state, kn, 2) = dkI
  
              dkI = s2_cache(J,i) * dij(i_I, i, i_state)
              dleat_s2(i_state, kn, 1) = dkI
              dleat_s2(i_state, kn, 2) = dkI
            end do
  
          end do
            
          komoned = .true.
  
negative.code: 
    call connect_to_taskserver(zmq_to_qp_run_socket,worker_id,thread)
  
    allocate (delta(N_states,0:N_det_non_ref, 2))
    allocate (delta_s2(N_states,0:N_det_non_ref, 2))
    allocate(komon(0:N_det_non_ref))
  
    allocate(hp(2,N_det_non_ref))
  