Added checks to ensure query names are unique and a valid query name is executed