Fixed some bugs for OSX