updating connections algorithm