Fixes to build on Mac

Haven't tested these patches on Windows or Linux, but nothing should be broken