Unhoist some more functions in query.js