Minor improvements for writting stats