Fix most compiler warnings and fix for OSX.