flag_count helper impmtd