Bug fixes to the energy storage code