Add tests

Includes tests, refinements to the documentation and a fix for an
inconsistent variable name.