adapt KEY_VAL to wchar and fix apparent thinko