diff --git a/src/cdi_key.c b/src/cdi_key.c
index 8b3169b2cc5f207435d1192ee6a4890bbe0bc858..b80d936df41b9cf64976cf9639131ab2e8cd4bc4 100644
--- a/src/cdi_key.c
+++ b/src/cdi_key.c
@@ -68,7 +68,7 @@ find_key(cdi_keys_t *keysp, int key)
 
   if (keysp->nelems == 0) return NULL;
 
-  for (size_t keyid = 0; keyid < keysp->nelems; keyid++)
+  for (uint16_t keyid = 0; keyid < keysp->nelems; keyid++)
     {
       cdi_key_t *keyp = &(keysp->value[keyid]);
       if (keyp->key == key) return keyp;  // Normal return
@@ -84,7 +84,7 @@ find_key_const(const cdi_keys_t *keysp, int key)
 
   if (keysp->nelems == 0) return NULL;
 
-  for (size_t keyid = 0; keyid < keysp->nelems; keyid++)
+  for (uint16_t keyid = 0; keyid < keysp->nelems; keyid++)
     {
       const cdi_key_t *keyp = &(keysp->value[keyid]);
       if (keyp->key == key) return keyp;  // Normal return
@@ -115,9 +115,9 @@ cdi_key_compare(cdi_keys_t *keyspa, cdi_keys_t *keyspb, int keynum)
   if (keypa->type != keypb->type) return 1;
   if (keypa->length != keypb->length) return 1;
 
-  if (keypa->type == KEY_BYTES) return (memcmp(keypa->v.s, keypb->v.s, (size_t) keypa->length) != 0);
-  if (keypa->type == KEY_FLOAT) return (IS_NOT_EQUAL(keypa->v.d, keypb->v.d));
-  if (keypa->type == KEY_INT) return (keypa->v.i != keypb->v.i);
+  if (keypa->type == KeyBytes) return (memcmp(keypa->v.s, keypb->v.s, (size_t) keypa->length) != 0);
+  if (keypa->type == KeyFloat) return (IS_NOT_EQUAL(keypa->v.d, keypb->v.d));
+  if (keypa->type == KeyInt) return (keypa->v.i != keypb->v.i);
 
   return 0;
 }
@@ -128,16 +128,16 @@ cdi_delete_key(cdi_key_t *keyp)
   if (keyp != NULL && keyp->length)  // key in use
     {
       keyp->length = 0;
-      if (keyp->type == KEY_BYTES)
+      if (keyp->type == KeyBytes)
         {
           if (keyp->v.s) Free(keyp->v.s);
           keyp->v.s = NULL;
         }
-      else if (keyp->type == KEY_FLOAT)
+      else if (keyp->type == KeyFloat)
         {
           keyp->v.d = 0.0;
         }
-      else if (keyp->type == KEY_INT)
+      else if (keyp->type == KeyInt)
         {
           keyp->v.i = 0;
         }
@@ -147,8 +147,8 @@ cdi_delete_key(cdi_key_t *keyp)
 void
 cdiDeleteVarKeys(cdi_keys_t *keysp)
 {
-  int nelems = keysp ? (int) keysp->nelems : 0;
-  for (int keyid = 0; keyid < nelems; keyid++)
+  uint16_t nelems = keysp ? keysp->nelems : 0;
+  for (uint16_t keyid = 0; keyid < nelems; keyid++)
     {
       cdi_delete_key(&(keysp->value[keyid]));
     }
@@ -168,20 +168,20 @@ cdiDeleteKeys(int cdiID, int varID)
 void
 cdiPrintVarKeys(cdi_keys_t *keysp)
 {
-  int nelems = keysp ? (int) keysp->nelems : 0;
-  for (int keyid = 0; keyid < nelems; keyid++)
+  uint16_t nelems = keysp ? (int) keysp->nelems : 0;
+  for (uint16_t keyid = 0; keyid < nelems; keyid++)
     {
       cdi_key_t *keyp = &(keysp->value[keyid]);
       if (keyp->length == 0) continue;
-      if (keyp->type == KEY_BYTES)
+      if (keyp->type == KeyBytes)
         {
           fprintf(stdout, "%d key %d length %d value %s\n", keyid + 1, keyp->key, keyp->length, keyp->v.s);
         }
-      else if (keyp->type == KEY_FLOAT)
+      else if (keyp->type == KeyFloat)
         {
           fprintf(stdout, "%d key %d value %g\n", keyid + 1, keyp->key, keyp->v.d);
         }
-      else if (keyp->type == KEY_INT)
+      else if (keyp->type == KeyInt)
         {
           fprintf(stdout, "%d key %d value %d\n", keyid + 1, keyp->key, keyp->v.i);
         }
@@ -220,9 +220,9 @@ static void
 cdi_define_key(const cdi_key_t *keyp, cdi_keys_t *keysp)
 {
   // clang-format off
-  if      (keyp->type == KEY_INT)   cdiDefVarKeyInt(keysp, keyp->key, keyp->v.i);
-  else if (keyp->type == KEY_FLOAT) cdiDefVarKeyFloat(keysp, keyp->key, keyp->v.d);
-  else if (keyp->type == KEY_BYTES) cdiDefVarKeyBytes(keysp, keyp->key, keyp->v.s, keyp->length);
+  if      (keyp->type == KeyInt)   cdiDefVarKeyInt(keysp, keyp->key, keyp->v.i);
+  else if (keyp->type == KeyFloat) cdiDefVarKeyFloat(keysp, keyp->key, keyp->v.d);
+  else if (keyp->type == KeyBytes) cdiDefVarKeyBytes(keysp, keyp->key, keyp->v.s, keyp->length);
   // clang-format on
 }
 
@@ -242,7 +242,7 @@ cdiDeleteKey(int cdiID, int varID, int key)
 void
 cdiCopyVarKeys(const cdi_keys_t *keysp1, cdi_keys_t *keysp2)
 {
-  for (size_t keyid = 0; keyid < keysp1->nelems; keyid++)
+  for (uint16_t keyid = 0; keyid < keysp1->nelems; keyid++)
     {
       const cdi_key_t *keyp = &(keysp1->value[keyid]);
       if (keyp->length > 0) cdi_define_key(keyp, keysp2);
@@ -300,7 +300,7 @@ cdiDefVarKeyInt(cdi_keys_t *keysp, int key, int value)
     {
       // if ( keyp->v.i != value )
       {
-        keyp->type = KEY_INT;
+        keyp->type = KeyInt;
         keyp->v.i = value;
         keyp->length = 1;
       }
@@ -371,7 +371,7 @@ cdiInqKeyInt(int cdiID, int varID, int key, int *value)
   const cdi_key_t *keyp = find_key_const(keysp, key);
   if (keyp != NULL && keyp->length == 1)  // key in use
     {
-      if (keyp->type == KEY_INT)
+      if (keyp->type == KeyInt)
         {
           *value = keyp->v.i;
           status = CDI_NOERR;
@@ -387,7 +387,7 @@ cdiInqVarKeyInt(const cdi_keys_t *keysp, int key)
   int value = 0;
 
   const cdi_key_t *keyp = find_key_const(keysp, key);
-  if (keyp && keyp->type == KEY_INT) value = keyp->v.i;
+  if (keyp && keyp->type == KeyInt) value = keyp->v.i;
 
   return value;
 }
@@ -400,7 +400,7 @@ cdiDefVarKeyFloat(cdi_keys_t *keysp, int key, double value)
 
   if (keyp != NULL)
     {
-      keyp->type = KEY_FLOAT;
+      keyp->type = KeyFloat;
       keyp->v.d = value;
       keyp->length = 1;
     }
@@ -470,7 +470,7 @@ cdiInqKeyFloat(int cdiID, int varID, int key, double *value)
   const cdi_key_t *keyp = find_key_const(keysp, key);
   if (keyp != NULL && keyp->length == 1)  // key in use
     {
-      if (keyp->type == KEY_FLOAT)
+      if (keyp->type == KeyFloat)
         {
           *value = keyp->v.d;
           status = CDI_NOERR;
@@ -501,7 +501,7 @@ cdiDefVarKeyBytes(cdi_keys_t *keysp, int key, const unsigned char *bytes, int le
         }
 
       memcpy(keyp->v.s, bytes, length_);
-      keyp->type = KEY_BYTES;
+      keyp->type = KeyBytes;
     }
 }
 
@@ -547,7 +547,7 @@ cdiInqVarKeyBytes(const cdi_keys_t *keysp, int key, unsigned char *bytes, int *l
   int val_len;
   if (keyp != NULL && (val_len = keyp->length) > 0)  // key in use
     {
-      if (keyp->type == KEY_BYTES)
+      if (keyp->type == KeyBytes)
         {
           if (val_len < *length)
             *length = val_len;
@@ -703,7 +703,7 @@ cdiInqVarKeyStringPtr(const cdi_keys_t *keysp, int key)
   const cdi_key_t *keyp = find_key_const(keysp, key);
   if (keyp != NULL)  // key in use
     {
-      if (keyp->type == KEY_BYTES) return (const char *) keyp->v.s;
+      if (keyp->type == KeyBytes) return (const char *) keyp->v.s;
     }
 
   return NULL;
@@ -714,7 +714,7 @@ cdiInitKeys(cdi_keys_t *keysp)
 {
   keysp->nalloc = MAX_KEYS;
   keysp->nelems = 0;
-  for (int i = 0; i < MAX_KEYS; ++i) keysp->value[i].length = 0;
+  for (uint16_t i = 0; i < MAX_KEYS; ++i) keysp->value[i].length = 0;
 }
 
 /*
diff --git a/src/cdi_key.h b/src/cdi_key.h
index 71755838c36dd14983b189ceeada51516a09a59c..8fa4f03637dff751c1ab7aba7bb29543eff38bb8 100644
--- a/src/cdi_key.h
+++ b/src/cdi_key.h
@@ -2,14 +2,15 @@
 #define CDI_KEY_H
 
 #include <stdio.h>
+#include <stdint.h>
 #include "cdi_limits.h"
 
 // CDI key
 typedef struct
 {
-  int key;     // CDI key
-  int type;    // KEY_INT, KEY_FLOAT, KEY_BYTES
-  int length;  // number of bytes in v.s
+  uint16_t key;   // CDI key
+  uint16_t type;  // KEY_INT, KEY_FLOAT, KEY_BYTES
+  int length;     // number of bytes in v.s
   union
   {
     int i;
@@ -20,16 +21,16 @@ typedef struct
 
 typedef struct
 {
-  size_t nalloc;  // number allocated >= nelems
-  size_t nelems;  // length of the array
+  uint16_t nalloc;  // number allocated >= nelems
+  uint16_t nelems;  // length of the array
   cdi_key_t value[MAX_KEYS];
 } cdi_keys_t;
 
 enum
 {
-  KEY_INT = 1,
-  KEY_FLOAT,
-  KEY_BYTES
+  KeyInt = 1,
+  KeyFloat,
+  KeyBytes
 };
 
 void cdiDefVarKeyInt(cdi_keys_t *keysp, int key, int value);
diff --git a/src/serialize.h b/src/serialize.h
index d771d704fcddae3935dae49c9361a7250b4a3761..c77c56707ac251c7867a1991f9a618f27a47ab38 100644
--- a/src/serialize.h
+++ b/src/serialize.h
@@ -42,16 +42,16 @@ serializeKeysGetPackSize(const cdi_keys_t *keysp, void *context)
       int type = keyp->type;
       packBuffSize += serializeGetSize(1, CDI_DATATYPE_INT, context);  // key
       packBuffSize += serializeGetSize(1, CDI_DATATYPE_INT, context);  // type
-      if (type == KEY_BYTES)
+      if (type == KeyBytes)
         {
           int length = keyp->length;
           packBuffSize += serializeGetSize(1, CDI_DATATYPE_INT, context) + serializeGetSize(length, CDI_DATATYPE_TXT, context);
         }
-      else if (type == KEY_INT)
+      else if (type == KeyInt)
         {
           packBuffSize += serializeGetSize(1, CDI_DATATYPE_INT, context);
         }
-      else if (type == KEY_FLOAT)
+      else if (type == KeyFloat)
         {
           packBuffSize += serializeGetSize(1, CDI_DATATYPE_FLT64, context);
         }
@@ -74,18 +74,18 @@ serializeKeysPack(const cdi_keys_t *keysp, void *buf, int buf_size, int *positio
       int type = keyp->type;
       serializePack(&key, 1, CDI_DATATYPE_INT, buf, buf_size, position, context);
       serializePack(&type, 1, CDI_DATATYPE_INT, buf, buf_size, position, context);
-      if (type == KEY_BYTES)
+      if (type == KeyBytes)
         {
           int length = keyp->length;
           serializePack(&length, 1, CDI_DATATYPE_INT, buf, buf_size, position, context);
           serializePack(keyp->v.s, length, CDI_DATATYPE_TXT, buf, buf_size, position, context);
           d ^= cdiCheckSum(CDI_DATATYPE_TXT, length, keyp->v.s);
         }
-      else if (type == KEY_INT)
+      else if (type == KeyInt)
         {
           serializePack(&keyp->v.i, 1, CDI_DATATYPE_INT, buf, buf_size, position, context);
         }
-      else if (type == KEY_FLOAT)
+      else if (type == KeyFloat)
         {
           serializePack(&keyp->v.d, 1, CDI_DATATYPE_FLT64, buf, buf_size, position, context);
         }
@@ -108,7 +108,7 @@ serializeKeysUnpack(const void *buf, int buf_size, int *position, cdi_keys_t *ke
       int key, type;
       serializeUnpack(buf, buf_size, position, &key, 1, CDI_DATATYPE_INT, context);
       serializeUnpack(buf, buf_size, position, &type, 1, CDI_DATATYPE_INT, context);
-      if (type == KEY_BYTES)
+      if (type == KeyBytes)
         {
           int length;
           serializeUnpack(buf, buf_size, position, &length, 1, CDI_DATATYPE_INT, context);
@@ -121,13 +121,13 @@ serializeKeysUnpack(const void *buf, int buf_size, int *position, cdi_keys_t *ke
           cdiDefVarKeyBytes(keysp, key, (unsigned char *) buffer, length);
           d2 ^= cdiCheckSum(CDI_DATATYPE_TXT, length, buffer);
         }
-      else if (type == KEY_INT)
+      else if (type == KeyInt)
         {
           int ival;
           serializeUnpack(buf, buf_size, position, &ival, 1, CDI_DATATYPE_INT, context);
           cdiDefVarKeyInt(keysp, key, ival);
         }
-      else if (type == KEY_FLOAT)
+      else if (type == KeyFloat)
         {
           double dval;
           serializeUnpack(buf, buf_size, position, &dval, 1, CDI_DATATYPE_FLT64, context);
diff --git a/src/zaxis.c b/src/zaxis.c
index a026f71361df46dfe756c1cffa89f54fb4ae07fb..447defcdffb6b1465a7312f073cd1715d630a264 100644
--- a/src/zaxis.c
+++ b/src/zaxis.c
@@ -1139,7 +1139,7 @@ static inline void
 zaxisCopyKeyStr(zaxis_t *zaxisptr1, zaxis_t *zaxisptr2, int key)
 {
   cdi_key_t *keyp = find_key(&zaxisptr1->keys, key);
-  if (keyp && keyp->type == KEY_BYTES)
+  if (keyp && keyp->type == KeyBytes)
     cdiDefVarKeyBytes(&zaxisptr2->keys, key, (const unsigned char *) keyp->v.s, (int) keyp->length);
 }