Bug fixes for invalid XML