fixed codebook and made stuff more readable