Fix flag state problems