reset @flagged_instance count at the end of each array loop