refactoring buffer functions