remove code repeatition when writing data to the shared buffer