Fixed potentially dangerous bug: was constructing edges wrongly!: with i residue number as the weight!