Fix a bunch of unsafe serialization issues