Fix type errors and documentation.

Fix a bunch of type errors and documentation problems.