fixed stats saving.. also fixed for when database is locked.. save it to file for later