Cleaned up XMLWriter
Fix infinite loop