Fixed bugs in the bitmask operations