Modified to work on my Mac, adding comments as well