Misc cleanups and ports to C++.