Modified to make compatible with OSX