     const unsigned int value_code = packed_value & ~0xf;
     
     // find prefix of the codeword and size of the prefix
-    int prefix_idx = encode ? preceding_zero_count * 16 + value_nbits : 0;
+    const int prefix_idx = preceding_zero_count * 16 + value_nbits;
     const unsigned int prefix_code = d_table->gcode[prefix_idx];
     const unsigned int prefix_nbits = prefix_code & 31;
     

        *last_dc = original_in_even;
    }
    
    // each thread gets codeword for its two pixels
    const bool encode = nonzero_follows || !tid;
    unsigned int even_code = gpujpeg_huffman_gpu_encode_value(zeros_before_even & 0xf, in_even, d_table_even, encode);
    unsigned int odd_code = gpujpeg_huffman_gpu_encode_value(zeros_before_odd & 0xf, in_odd, d_table_ac, encode);
    
    // special case for last zero coefficient
    if(tid == 31 && in_odd == 0) {


__device__ static unsigned int
gpujpeg_huffman_gpu_encode_value(const int preceding_zero_count, const int value,
                                 const struct gpujpeg_table_huffman_encoder * const d_table)
{
    // value bits are in MSBs (left aligned) and bit size of the value is in LSBs (right aligned)
    const unsigned int packed_value = gpujpeg_huffman_value_decomposition[4096 + value];
