Various fixes to allow building on Max OSX