This should change absolutely nothing in any output file.
But it's pretty wild how little was accomplished by so much code here. Not only was it overly complicated, it created and accessed several global variables.
This finally gets rid of
BTaggingFlags. Good riddance. Hopefully. I haven't tested this code. Anyway let's see what breaks.