Refactor XML serialization code.