refactored buffer/string writing to trait style