update wards algorithm