Fix Mac OS X bugs