replaced a few bitmask operations by modulo operations