Common code for OSX and iOS