Fix compile warnings and errors on MSVC