Added energy function