moved query function to global, and have each page call it when loaded