fixed bug in codebook generation.