Various smaller fixes and cleanups.

See commit messages.