Refactor code and codebook