portability improvements mainly for osx