Small code refactor
Refactor into generic query

Querying is now generic so that more flexibility is made available to
the attacker.