Various fixes for MinGW build