Fix flag count bug