Move some logic from the parser into the db proper.
Some small clarity changes.