some code changes in sorting