diff --git a/libcelt/celt.c b/libcelt/celt.c
index 8995b7aec4b0c685d5e67b41bc6966109aa1de62..bfc15614cd943d62e164b8379a89a355df575259 100644
--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -923,10 +923,10 @@ int celt_encode_with_ec_float(CELTEncoder * restrict st, const celt_sig * pcm, i
      return CELT_BAD_ARG;
 
    frame_size *= st->upsample;
-   for (LM=0;LM<4;LM++)
+   for (LM=0;LM<=st->mode->maxLM;LM++)
       if (st->mode->shortMdctSize<<LM==frame_size)
          break;
-   if (LM>=MAX_CONFIG_SIZES)
+   if (LM>st->mode->maxLM)
       return CELT_BAD_ARG;
    M=1<<LM;
    N = M*st->mode->shortMdctSize;
@@ -2178,10 +2178,10 @@ int celt_decode_with_ec_float(CELTDecoder * restrict st, const unsigned char *da
       return CELT_BAD_ARG;
 
    frame_size *= st->downsample;
-   for (LM=0;LM<4;LM++)
+   for (LM=0;LM<=st->mode->maxLM;LM++)
       if (st->mode->shortMdctSize<<LM==frame_size)
          break;
-   if (LM>=MAX_CONFIG_SIZES)
+   if (LM>st->mode->maxLM)
       return CELT_BAD_ARG;
    M=1<<LM;
 
diff --git a/libcelt/modes.c b/libcelt/modes.c
index ca509921e82ee5882882ceb2b233991a1e50d12f..f33cfab3ff24a243c2b2213033412b87098d7208 100644
--- a/libcelt/modes.c
+++ b/libcelt/modes.c
@@ -247,11 +247,13 @@ static void compute_allocation_table(CELTMode *mode)
 CELTMode *celt_mode_create(celt_int32 Fs, int frame_size, int *error)
 {
    int i;
-   int res;
    CELTMode *mode=NULL;
+#ifdef CUSTOM_MODES
+   int res;
    celt_word16 *window;
    celt_int16 *logN;
    int LM;
+#endif
 #ifdef STDIN_TUNING
    scanf("%d ", &MIN_BINS);
    scanf("%d ", &BITALLOC_SIZE);
diff --git a/libcelt/modes.h b/libcelt/modes.h
index 43bdccc0eb0e09bea5996304d6538d8aae99fc1d..d874d7b8493e4ad8c40cb13990420b80445e9b6e 100644
--- a/libcelt/modes.h
+++ b/libcelt/modes.h
@@ -41,8 +41,6 @@
 #include "entenc.h"
 #include "entdec.h"
 
-#define MAX_CONFIG_SIZES 5
-
 #define CELT_BITSTREAM_VERSION 0x8000000f
 
 #define MAX_PERIOD 1024