added error checking, wchar_t finish