B encoding code is unstable. needs more coding and testing