     const int prefix_idx = preceding_zero_count * 16 + out_nbits;
     out_cword |= d_table->code[prefix_idx] << out_nbits;
     out_nbits += d_table->size[prefix_idx];
+    
+    // compose packed codeword with its size
+    return out_nbits | (out_cword << (32 - out_nbits));
 }
 
 

}


__device__ static void
gpujpeg_huffman_gpu_encode_value(unsigned int & out_nbits, unsigned int & out_cword, const int preceding_zero_count, const int value,
                                 const struct gpujpeg_table_huffman_encoder * const d_table) {
    out_cword = value;
    int absolute = value;
    if ( value < 0 ) {
        // valu eis now absolute value of input

    }

    // Find the number of bits needed for the magnitude of the coefficient
    unsigned int out_nbits = 0;
    while ( absolute ) {
        out_nbits++;
        absolute >>= 1;
