refactor query.js