make FlushBuffer thread-safe
rewrite all codes