Fix build.

Various fixes from @MWisBest.