added sorting fuction