fix logic fail in BGen.