made sorting a function