Turning thermal energy into electricity