fixed flag count bug