There is a very subtle problem with the diagonal elements of H that leads to the calculation being wrong. Values on the diagonal are swapped. Still looking into why this is the case