added function to write