canonicalize codes: found bug on bd = 4. not solved