added writeBuffer