Partial sorting logic