fixed write and overwrite functionality