added flag count threshold