added the code for the refined codebook