Fix bugs on Mac OS X