Correct some errors in energy calculation