Savepoints, templates and flag defaults.

- Use savepoints rather than virtual transactions.
- Allow templates to be used outside the HTTP system.
- Make flag defaults work correctly.