Fix #24: serialization corner cases.
Merge pull request #31 from SimonSapin/serialization

Fix #24: serialization corner cases.