patched for MSVC compilation