add ugly casts to allow building with MSVC