Improved code to generate correct xar.