refactoring: make QueryBuilder toplevel class (review comments)