 gpujpeg_huffman_gpu_encoder_encode_block(int16_t * block, uint8_t * &data_compressed, int * s_in, int * s_out, int &out_size, int *last_dc, int tid,
                 struct gpujpeg_table_huffman_encoder* d_table_dc, struct gpujpeg_table_huffman_encoder* d_table_ac)
 {
+    // each thread loads a pair of values (pair after zigzag reordering)
+    const int load_idx = tid * 2;
+    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]];
+    
+    
+    
+    
+    
+    // save value into shared memory
+    s_in[load_idx] = in_even;
+    s_in[load_idx + 1] = in_odd;
+    
     int result = 0;
     if(0 == tid) {
         int & dc = *last_dc;

            put_bits = 0;
            out_size = 1;
        }
        result = gpujpeg_huffman_gpu_encoder_encode_block(put_value, put_bits, dc, block, data_compressed, d_table_dc, d_table_ac);
    }
    return __ballot(result);
    
    
//     // each thread loads pair of values (pair after zigzag reordering)
//     const int load_idx = tid * 2;
//     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 count of consecutive zeros before even value
//     // TODO: reimplement after getting it all to work

    int r = 0;
    for ( int k = 1; k < 64; k++ ) 
    {
        temp = data[k];
        if ( temp == 0 ) {
            r++;
        }
