make it compile on OSX
Various fixes to make it somewhat work