added remove flag function