fix use of bitmask
improve by const reference