fixed some flag bugs