Create a single function to take care of sorting results from queries

## Changes in this PR:
* Create a single function to take care of sorting results from queries
* Make sorting function accept the sorting method as a parameter
* Sorting method can be 'single', 'multiple' or 'teams', depending on the type of results being sorted