fix aprior algorithm