diff --git a/include/internal/generic/fmpi_futhark_generic.h b/include/internal/generic/fmpi_futhark_generic.h
index 39ebf6d22241aad74d06fc0c578fae8cb5a35ef0..139cf0a9bb2c519cd1a442f0e6d243dae3c73628 100644
--- a/include/internal/generic/fmpi_futhark_generic.h
+++ b/include/internal/generic/fmpi_futhark_generic.h
@@ -42,8 +42,11 @@ struct fmpi_futhark_ctx;
 #define FMPI_FUTHARK_TYPES \
     FMPI_TYPE_REAL
 
+#define FMPI_PRIV_FUTHARK_FUNC_IDX(d, t) \
+    (((t) * FMPI_DIM_MAX) + (d) - 1)
+
 #define FMPI_PRIV_FUTHARK_ARRAY_ENTRY(D, T) \
-    [FMPI_TYPE_##T * (FMPI_DIM_MAX) + ((D)-1)] = fmpi_futhark_new_##D##d_##T
+    [FMPI_PRIV_FUTHARK_FUNC_IDX(D, FMPI_TYPE_##T)] = fmpi_futhark_new_##D##d_##T
 
 #define FMPI_FUTHARK_ARRAY_ENTRY_LIST(D) \
     CPL_MAP_FIXED(FMPI_PRIV_FUTHARK_ARRAY_ENTRY, CPL_COMMA, (D), FMPI_FUTHARK_TYPES)
diff --git a/src/fmpi_futhark.c b/src/fmpi_futhark.c
index 22760b42a25da3fbbae2c6e27fea52b96ea83503..706880c58afdafb6e60ac6a09ae5f04766bdcae9 100644
--- a/src/fmpi_futhark.c
+++ b/src/fmpi_futhark.c
@@ -148,7 +148,7 @@ void * fmpi_futhark_new_data(
     assert(ctx != NULL);
     assert(data != NULL);
     assert(dim_cnt <= FMPI_DIM_MAX);
-    const size_t idx = (type * (FMPI_DIM_MAX) + ((dim_cnt)-1));
+    const size_t idx = FMPI_PRIV_FUTHARK_FUNC_IDX(dim_cnt, type);
     return fmpi_futhark_new_data_func_list[idx](ctx, data, x, y, z);
 }
 
@@ -166,14 +166,14 @@ void * fmpi_futhark_new_##D##d_##T( \
     } \
     fmpi_futhark_sync(ctx); \
     return data; \
-}\
+} \
 void fmpi_futhark_free_##D##d_##T( \
     const struct fmpi_futhark_ctx * const ctx, void * const array \
 ){ \
     _Static_assert((D) <= FMPI_DIM_MAX, ""); \
     assert(ctx != NULL); \
     assert(array != NULL); \
-    fmpi_futhark_sync(ctx);\
+    fmpi_futhark_sync(ctx); \
     const int err = futhark_free_##T##_##D##d(ctx->ctx, array); \
     if(err != 0) { \
         fmpi_futhark_check_error(ctx, CPL_STRINGIFY(futhark_free_##T##_##D##d)); \