Many more bug fixes relating to serialization