Some build tweaks

Some fixes and tweaks for a clean build. See commits for details.