Fixed a bug in generating bitmask