set flag and reset flag