added checks for well formed xml