Various fixes to write_all