need a better way to serialize/deserialize function