fix bug in flush method