Slight optimization and refactoring for buffers