Improve serialization
Add tests