refactor on buffer writes