Add flush buffer function