sorting logic update