Fix many serialization bugs