adjust the sequence of setting the flag