added function sortresults