Write codebook