Unified code in main.js & txtQuery.js