fixed the energy calculation