move resused code into QueryBuilder