Serialization and deserialization fixes and refactoring.
Preparation for argc argv format.