fixing the serialize and deserialize function