Fixed more bugs in energy computation.