Function Sort implemented