Sort function Implemented