Added code to sort and extract the best weight