Fixes to get this to build on Darwin, and fixing of unit test problems