Updated code to work better on Mac.