More checks to try to ensure that invalid XML isnt' generated