refactored add text to buffer implementation