added codebook function