Some fixes to build cleanly on OSX