Updated for compatibility with OSX