Fixed XML handling bugs