codebook and slight r code changes