going back on the sort function - refactor needed