lots of fix for mingw.