Various OSX build fixes

More accumulating in this branch over time, feel free to merge whenever you want and I'll create a new pull request :)