improve the serialize/deserialize function