Refactor Index.sort and fix hidden+highlighted threads should be at the end.