Refactor query class, subclass, adapt tests.