Add sort function according to categories