fix bit decoding and start encodeing