Fix bugs when deserializing a model