several fixes and restructurizations to energy calculation