Implemented a Sort() function