Move the sorting of query args into its own function - thanks @manishtomar