fix flush logic