Added logging to see what is happening when stats are not written out on close.