some refactoring
sort queries by name