Some fixes and adding to ability to write into an existing file