Cleaner and more correct handling of bitflags