anchor.diff:              deallocate(ueg_basis_dim, stat=ierr)
               call check_deallocate('ueg_basis_dim', ierr)
           end if
  +        if (allocated(ueg_ternary_conserve)) then
  +            deallocate(ueg_ternary_conserve, stat=ierr)
  +            call check_deallocate('ueg_ternary_conserve', ierr)
  +        end if
   
       end subroutine end_ueg_indexing
   
  
positive.code: 
          ! Now fill in the values for the alpha orbitals which are in the basis.
          forall (i=1:nbasis:2) ueg_basis_lookup(dot_product(basis_fns(i)%l, ueg_basis_dim) + ueg_basis_origin) = i
  
      end subroutine init_ueg_indexing
  
  
negative.code: 
          ! Create arrays and data for index mapping needed for UEG.
  
          use basis, only: basis_fns, nbasis, bit_lookup, basis_length
          use system, only: box_length, ueg_ecutoff, ndim
  
          use checking, only: check_allocate
          use utils, only: tri_ind
  
          integer :: ierr, i, j, a, ind, N_kx, k_min(ndim), bit_pos, bit_el, k(ndim)
  
          ueg_basis_max = ceiling(sqrt(2*ueg_ecutoff))
  
  