write comments and optimize GammaEncoder