Fix XmlSerialization and some refactoring