fix quality calculation