Support building on win32 and some other fixes