A few tiny changes before I start adding a form.
Massive refactorings - untested.

In preparation for adding manual form input, and to make code a bit
easier to follow, hopefully. Also shipped out settings and schema to
different files.