implement write to buffer