use wrapped compact for intersection
diff --git a/src/theta_sketch_c_adapter.cpp b/src/theta_sketch_c_adapter.cpp
index 7b09ec9..8f46280 100644
--- a/src/theta_sketch_c_adapter.cpp
+++ b/src/theta_sketch_c_adapter.cpp
@@ -211,9 +211,9 @@
   }
 }
 
-void theta_intersection_update(void* interptr, const void* sketchptr) {
+void theta_intersection_update(void* interptr, const void* buffer, unsigned length) {
   try {
-    static_cast<theta_intersection_pg*>(interptr)->update(*static_cast<const theta_sketch_pg*>(sketchptr));
+    static_cast<theta_intersection_pg*>(interptr)->update(wrapped_compact_theta_sketch_pg::wrap(buffer, length));
   } catch (std::exception& e) {
     pg_error(e.what());
   }
diff --git a/src/theta_sketch_c_adapter.h b/src/theta_sketch_c_adapter.h
index 4aaf438..4c716c1 100644
--- a/src/theta_sketch_c_adapter.h
+++ b/src/theta_sketch_c_adapter.h
@@ -49,7 +49,7 @@
 
 void* theta_intersection_new_default();
 void theta_intersection_delete(void* interptr);
-void theta_intersection_update(void* interptr, const void* sketchptr);
+void theta_intersection_update(void* interptr, const void* buffer, unsigned length);
 void* theta_intersection_get_result(const void* interptr);
 
 void* theta_a_not_b(const void* sketchptr1, const void* sketchptr2);
diff --git a/src/theta_sketch_pg_functions.c b/src/theta_sketch_pg_functions.c
index 2ef8517..c6678f4 100644
--- a/src/theta_sketch_pg_functions.c
+++ b/src/theta_sketch_pg_functions.c
@@ -165,7 +165,6 @@
 Datum pg_theta_sketch_intersection_agg(PG_FUNCTION_ARGS) {
   void* interptr;
   bytea* sketch_bytes;
-  void* sketchptr;
 
   MemoryContext oldcontext;
   MemoryContext aggcontext;
@@ -188,9 +187,7 @@
   }
 
   sketch_bytes = PG_GETARG_BYTEA_P(1);
-  sketchptr = theta_sketch_deserialize(VARDATA(sketch_bytes), VARSIZE(sketch_bytes) - VARHDRSZ);
-  theta_intersection_update(interptr, sketchptr);
-  theta_sketch_delete(sketchptr);
+  theta_intersection_update(interptr, VARDATA(sketch_bytes), VARSIZE(sketch_bytes) - VARHDRSZ);
 
   MemoryContextSwitchTo(oldcontext);
 
@@ -362,8 +359,6 @@
 Datum pg_theta_sketch_intersection(PG_FUNCTION_ARGS) {
   const bytea* bytes_in1;
   const bytea* bytes_in2;
-  void* sketchptr1;
-  void* sketchptr2;
   void* interptr;
   void* sketchptr;
   struct ptr_with_size bytes_out;
@@ -371,15 +366,11 @@
   interptr = theta_intersection_new_default();
   if (!PG_ARGISNULL(0)) {
     bytes_in1 = PG_GETARG_BYTEA_P(0);
-    sketchptr1 = theta_sketch_deserialize(VARDATA(bytes_in1), VARSIZE(bytes_in1) - VARHDRSZ);
-    theta_intersection_update(interptr, sketchptr1);
-    theta_sketch_delete(sketchptr1);
+    theta_intersection_update(interptr, VARDATA(bytes_in1), VARSIZE(bytes_in1) - VARHDRSZ);
   }
   if (!PG_ARGISNULL(1)) {
     bytes_in2 = PG_GETARG_BYTEA_P(1);
-    sketchptr2 = theta_sketch_deserialize(VARDATA(bytes_in2), VARSIZE(bytes_in2) - VARHDRSZ);
-    theta_intersection_update(interptr, sketchptr2);
-    theta_sketch_delete(sketchptr2);
+    theta_intersection_update(interptr, VARDATA(bytes_in2), VARSIZE(bytes_in2) - VARHDRSZ);
   }
   sketchptr = theta_intersection_get_result(interptr);
   theta_intersection_delete(interptr);