quality flag bug fixing