fix flag handling