before buffer function