Fix serialization/deserialization.
Do refactoring.
Fix most compile errors.