FINAL The energy function