Fixed flag bugs