Various fixes to make it compile on Windows