refactor flush