final version with codebook