Fix statistics-related bugs