rewriting some queries to use get variable and check if query is set