Added sort function