XMLWriter refactored