Fixed various broken bits of flag handling.