functioning code for OS X