Several OSX fixes, needs testing