update the codebook