adding write and append method, with corresponding tests