List sort refactoring and bug fix.
List sort refactoring and bug fixes.