Fix broken tests.
Rename `mangle` to `finalize`.

Also, some cleanup.