refactored XML export loops