code updated to work on mac