improved some error handling in energy.lua