Refactor sort and cleanup code from onHistoryUpdated() and onGroupsUpdated() cleanupList().