XML writing bug fixes