Refactor the filter function to be a simple query clause applicator.
Initial work on authorization hooks.
Fix a few errors.