optimization: using bitmask instead of "if"s