Bug fixes for MSVC