Bug fixes and new script to compute energy