Adding sort function