improve logic for updating edges