improved bootstrap sorting logic