diff --git a/collector.c b/collector.c
index e1e00cf..dcb9695 100644
--- a/collector.c
+++ b/collector.c
@@ -470,7 +470,7 @@ pgws_collector_main(Datum main_arg)
 								send_profile(profile_hash, mqh);
 								break;
 							default:
-								AssertState(false);
+								Assert(false);
 						}
 						break;
 					case SHM_MQ_DETACHED:
@@ -480,7 +480,7 @@ pgws_collector_main(Datum main_arg)
 										"detached")));
 						break;
 					default:
-						AssertState(false);
+						Assert(false);
 				}
 				shm_mq_detach_compat(mqh, pgws_collector_mq);
 			}
diff --git a/compat.h b/compat.h
index 3f471ce..32874f7 100644
--- a/compat.h
+++ b/compat.h
@@ -15,6 +15,7 @@
 #include "access/tupdesc.h"
 #include "miscadmin.h"
 #include "storage/shm_mq.h"
+#include "utils/guc_tables.h"
 
 static inline TupleDesc
 CreateTemplateTupleDescCompat(int nattrs, bool hasoid)
@@ -65,4 +66,18 @@ InitPostgresCompat(const char *in_dbname, Oid dboid,
 #endif
 }
 
+static inline void
+get_guc_variables_compat(struct config_generic ***vars, int *num_vars)
+{
+	Assert(vars != NULL);
+	Assert(num_vars != NULL);
+
+#if PG_VERSION_NUM >= 160000
+	*vars = get_guc_variables(num_vars);
+#else
+	*vars = get_guc_variables();
+	*num_vars = GetNumConfigOptions();
+#endif
+}
+
 #endif
diff --git a/pg_wait_sampling.c b/pg_wait_sampling.c
index 783c839..eaa0327 100644
--- a/pg_wait_sampling.c
+++ b/pg_wait_sampling.c
@@ -198,8 +198,7 @@ setup_gucs()
 				profile_pid_found = false,
 				profile_queries_found = false;
 
-	guc_vars = get_guc_variables();
-	numOpts = GetNumConfigOptions();
+	get_guc_variables_compat(&guc_vars, &numOpts);
 
 	for (i = 0; i < numOpts; i++)
 	{
@@ -452,7 +451,6 @@ pg_wait_sampling_get_current(PG_FUNCTION_ARGS)
 	{
 		MemoryContext		oldcontext;
 		TupleDesc			tupdesc;
-		WaitCurrentContext 	*params;
 
 		funcctx = SRF_FIRSTCALL_INIT();
 
@@ -546,7 +544,7 @@ pg_wait_sampling_get_current(PG_FUNCTION_ARGS)
 		else
 			nulls[2] = true;
 
-		values[3] = Int64GetDatumFast(item->queryId);
+		values[3] = UInt64GetDatum(item->queryId);
 		tuple = heap_form_tuple(funcctx->tuple_desc, values, nulls);
 
 		SRF_RETURN_NEXT(funcctx, HeapTupleGetDatum(tuple));
@@ -732,11 +730,11 @@ pg_wait_sampling_get_profile(PG_FUNCTION_ARGS)
 			nulls[2] = true;
 
 		if (pgws_collector_hdr->profileQueries)
-			values[3] = Int64GetDatumFast(item->queryId);
+			values[3] = UInt64GetDatum(item->queryId);
 		else
 			values[3] = (Datum) 0;
 
-		values[4] = Int64GetDatumFast(item->count);
+		values[4] = UInt64GetDatum(item->count);
 
 		tuple = heap_form_tuple(funcctx->tuple_desc, values, nulls);
 
@@ -848,7 +846,7 @@ pg_wait_sampling_get_history(PG_FUNCTION_ARGS)
 		else
 			nulls[3] = true;
 
-		values[4] = Int64GetDatumFast(item->queryId);
+		values[4] = UInt64GetDatum(item->queryId);
 		tuple = heap_form_tuple(funcctx->tuple_desc, values, nulls);
 
 		history->index++;
