modified for Mac