Fix flag handling