Changed the algorithm of sorting widgets