Various fixes and changes to the build system