fix flush out of loop