diff --git a/lzw.c b/lzw.c
index 48829ab4d9a3e7dfecedc35e253d4cac68e789cf..81c17060b021e1cefef3be3b3edbad0f95d65b01 100644
--- a/lzw.c
+++ b/lzw.c
@@ -8,7 +8,7 @@
 
 #include "lzw.h"
 
-FILE *debug; // DEBUG
+//FILE *debug; // DEBUG
 
 #define BITLIMIT_9 (ctx->earlychange ? 511 : 512)
 #define BITLIMIT_10 (ctx->earlychange ? 1023 : 1024)
@@ -89,6 +89,12 @@ act_LZW_clear(const HParseResult *p, void *u)
 	return H_MAKE_BYTES(NULL, 0);
 }
 
+HParsedToken*
+act_LZW_clear_and_firstcode(const HParseResult *p, void *u)
+{
+	return p->ast->seq->elements[1];
+}
+
 bool
 validate_LZW_9bitcodeword(HParseResult *p, void *u)
 {
@@ -422,7 +428,9 @@ void init_LZW_parser()
 	H_AVDRULE(LZW_literal, h_choice(LZW_9bitlitspec, LZW_10bitlitspec, LZW_11bitlitspec, LZW_12bitlitspec, NULL), context);
 	H_ADRULE(LZW_codeword, h_choice(LZW_9bitcodeword, LZW_10bitcodeword, LZW_11bitcodeword, LZW_12bitcodeword, NULL), context);
 
-	H_ADRULE(LZW_body, h_many1(h_butnot(h_choice(LZW_literal, h_ignore(LZW_clear), LZW_codeword, NULL), LZW_eod)), context);
+	H_ADRULE(LZW_clear_and_firstcode, h_sequence(h_ignore(LZW_clear), LZW_firstcode, NULL), context);
+
+	H_ADRULE(LZW_body, h_many1(h_butnot(h_choice(LZW_literal, LZW_clear_and_firstcode, LZW_codeword, NULL), LZW_eod)), context);
 
 	H_ADRULE(LZW_data, h_sequence(LZW_clear, LZW_firstcode, LZW_body, LZW_eod, LZW_remainingbits, NULL), context);
 	p_lzwdata = LZW_data;