Fix a bug where the writing of the end of the stats wasn't working