Display error messages when a domain is not a primary.

Split off templates into sub-templates and a layout template.
Loads of cleanup, trying to make things pretty.