Added serialize and deserialize methods.