added sorting fucntion