update sorting function