fixed flag bug