make IME flag handling more reliable