Numerous tweaks to allow compile on OSX

Thanks again to Fraggle! More work to be done...