sorting results before returning