Fixing Sort function