buf refactor