Modified Code for Mac