     const unsigned int value_code = packed_value & ~0xf;
     
     // find prefix of the codeword and size of the prefix
-    const int prefix_idx = preceding_zero_count * 16 + value_nbits;
-    const unsigned int prefix_code = d_table->gcode[prefix_idx];
+    const unsigned int prefix_code = d_table->gcode[preceding_zero_count_idx | value_nbits];
     const unsigned int prefix_nbits = prefix_code & 31;
     
     // compose packed codeword with its size

    int in_even = block[gpujpeg_huffman_gpu_encoder_order_natural[load_idx]];
    const int in_odd = block[gpujpeg_huffman_gpu_encoder_order_natural[load_idx + 1]];
    
    // compute preceding zero count for even coefficient
    const unsigned int nonzero_mask = (1 << tid) - 1;
    const unsigned int nonzero_bitmap_0 = 1 | __ballot(in_even);  // DC is always treated as nonzero
    const unsigned int nonzero_bitmap_1 = __ballot(in_odd);
    const unsigned int nonzero_bitmap_pairs = nonzero_bitmap_0 | nonzero_bitmap_1;
    
    const int zero_pair_count = __clz(nonzero_bitmap_pairs & nonzero_mask);
    int zeros_before_even = 2 * (zero_pair_count + tid - 32);
    if((0x80000000 >> zero_pair_count) > (nonzero_bitmap_1 & nonzero_mask)) {
        zeros_before_even++;
    }
    
    // true if any nonzero pixel follows thread's odd pixel



__device__ static unsigned int
gpujpeg_huffman_gpu_encode_value(const int preceding_zero_count_idx, 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)
