adding flag counting feature