Different way of computing Hamiltonian