Bunch of compatibility fixes for Windows