Added code from experimenting with energy tracking.