Changes and fixes for OSX support