This fixes obvious overflows when checking bitflags, who knows how much undiscovered issues exists in the code still..