R script tweaks and codebook