add backgound flush function, but not tested.