modified for mac osx