Adopt osx code for recent changes