Introduce a more efficient implementation of QueryUtils
Code cleanup