refactoring query.js to be leaner, and wrap trailing space issue of databank