refactor common text buffer stuff into base class.