Make query classes non-final

Fixes #871