Added a sorting function