Change the queries to a function, changed previous queries to http_build_query