Fix and improve TOML writing