more sensible looping for bitflag
reformat