edited for mac compatibility