buffer refactoring