Fix serialization bugs