Multiple changes to get it working on Windows