Fixed code for Mac