refactored code for xml rendering