Numerous fixes to build cleanly; still lots of untyped pointers though