optimize putbits functions, and remove some unused functions