Added a highorder function to accomidate sortingby