Fix serialization logic.