Fixing the reading and writing of stats in the database