API and coding style improvements.

See commit messages for details.