function sort implemented