Several fixes for OSX