added function writeto()