Added calculating energy