some refactoring of Query.js