Move QUAL check further up to reduce runtime.