Fix compilation errors and OSX build