More robust OSX implementation