refactored adding data to buffer