More efficient implementation of `get_total_energy`. Closes #146