Clean up the Settings codebase.

* add more tests
* add documentation
* raise helpful error messages