Fixed bugs with serialization