List sort refactoring and bug fixes.