portability fixes for Mac OSX