refactors output buffer and tests