improve hamiltonian example