Fix a few xml wellformedness issues
Clean out a few warnings on potential resource leakage