Previous commit missed most changes; this commit contains the rest
(and fixes the build).